Проблема с ошибками Gradle и Boolean при попытке построить APK,Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Проблема с ошибками Gradle и Boolean при попытке построить APK,

Сообщение Anonymous »

Я пытаюсь построить APK в Android Studio с Flutter и Gradle. Я получил следующие ошибки и не уверен, как их разрешить. Я застрял в петле, изменяющем форматирование вывода, за которым следуют логические ошибки, подобные тому, который я поставлял. Я использовал смесь CATGPT и Gemini, чтобы помочь разрешить ошибки, но оба застряли в циклах в отношении логических ошибок или выводов, не настроенных.

Код: Выделить всё

e: file:///C:/Users/Zaria/new_sorry_tally/android/app/build.gradle.kts:70:29: Type mismatch: inferred type is Unit but Boolean was expected
e: file:///C:/Users/Zaria/new_sorry_tally/android/app/build.gradle.kts:80:13: Expected a value of type Boolean
e: file:///C:/Users/Zaria/new_sorry_tally/android/app/build.gradle.kts:80:20: Unresolved reference: outputFileName

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\Zaria\new_sorry_tally\android\app\build.gradle.kts' line: 70

* What went wrong:
Script compilation errors:

Line 70:         variant.outputs.all { output ->
^ Type mismatch: inferred type is Unit but Boolean was expected

Line 80:             output.outputFileName = outputFile.name
^ Expected a value of type Boolean

Line 80:             output.outputFileName = outputFile.name
^ Unresolved reference: outputFileName
< /code>
import com.android.build.gradle.api.ApplicationVariant
import java.io.File

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("dev.flutter.flutter-gradle-plugin")
id("com.google.gms.google-services") // Google services plugin for Firebase
id("com.google.firebase.crashlytics") // Firebase Crashlytics plugin
}

android {
namespace = "com.zaria.new_sorry_tally"
compileSdk = 35
ndkVersion = "27.0.12077973"

defaultConfig {
applicationId = "com.zaria.new_sorry_tally"
minSdk = 21
targetSdk = 35
versionCode = 1
versionName = "1.0"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = "17"
}

buildTypes {
getByName("debug") {
isMinifyEnabled = false
}
getByName("release") {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
}
}

dependencies {
// Material Design and AppCompat
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.appcompat:appcompat:1.6.1")

// Firebase SDKs
implementation("com.google.firebase:firebase-analytics:21.6.0")
implementation("com.google.firebase:firebase-firestore:24.10.1")
implementation("com.google.firebase:firebase-crashlytics:18.6.5")

// Play Services for Firebase and Analytics
implementation("com.google.android.gms:play-services-measurement-api:21.6.0")
implementation("com.google.android.gms:play-services-measurement-impl:21.6.0")
}
}

// Apply the Google services plugin at the end
apply(plugin = "com.google.gms.google-services")

// After evaluate block for customizing APK output names
afterEvaluate {
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
val outputFileName = if (variant.buildType.name == "debug") {
"app-debug.apk"
} else {
"app-release.apk"
}

// Correct way to modify APK output name in newer AGP versions
val outputFile = File(buildDir, "outputs/apk/${variant.buildType.name}/$outputFileName")

// Set the output file name correctly for newer AGP versions
output.outputFile = outputFile
}
}
}
Я попытался изменить выходное имя и другие трюки, которые я нашел, используя Chatgpt.


Подробнее здесь: https://stackoverflow.com/questions/796 ... -build-apk
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»