我正在尝试制作我的第一个Flutter Android捆绑包,进展并不顺利。
我用Android Studio创建了我的项目,然后制作了我的应用程序。现在我需要在firebase应用程序部署上设置它。创建ios IPA超级容易。现在是时候制作Android捆绑包了:(
编辑:Android Studio的初始错误是由于没有使用正确的构建appbundle命令造成的。它给我的错误与flutter构建appbundle相同。
我在终端中尝试终端命令“flutter build appbundle”。我得到了相同的错误“错误插件与id 'com.android.application'找不到”
来自终端的错误
💪 Building with sound null safety 💪
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/user/AndroidStudioProjects/PrjName/android/app/build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> Plugin with id 'com.android.application' not found.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 345ms
Running Gradle task 'bundleRelease'... 1 037ms
Gradle task bundleRelease failed with exit code 1
编辑:下面是我的build.gradel文件:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
// START: FlutterFire Configuration
apply plugin: 'com.google.gms.google-services'
// END: FlutterFire Configuration
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "***********************"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
我查了谷歌和这里的答案,发现过时的“答案”,不工作的地方98%是与常规android项目,而不是flutter项目。尝试了一些,但没有改变任何东西。
Android Studio是2周前重新安装的。我删除了我的~/.gradle,也没有改变任何东西。我确实要求./gradlew更新,这没有改变任何东西。尝试从hombrew安装gradle,但接缝抖动,Android Studio不关心让我改变gradle目录。
那我能怎么办?
找到了一个相关的question,但没有答案,很遗憾。:(
1条答案
按热度按时间rdlzhqv91#
发现了我的问题。这真的很愚蠢。我的根build.gradle是空的。不知何故,使用firebase工具添加firebase时,意外地清除了根build.gradle中的所有内容。
我必须创建一个新的flutter项目来将内容复制到我当前的项目中。现在可以工作了。