自两天以来,我一直在尝试解决此问题,并且我还尝试了Stack Overflow上有关此问题的解决方案,但未成功。 我遵循的所有步骤均来自 将Firebase添加到您的Android应用指南中(Firebase官方提供的步骤)
PROJECT-LEVEL Build.gradle:
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
APP-LEVEL Build.gradle:
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'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.loginapp"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics:17.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
Pubspec.yaml文件:
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
firebase_auth: ^0.14.0+9
dev_dependencies:
flutter_test:
sdk: flutter
Gradle-wrapper.properties:
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
错误:
PS D:\flutterworks\bhund> flutter run
Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with
"--enable-software-rendering".
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle... 5.1s
Resolving dependencies...
* Error running Gradle:
ProcessException: Process "D:\flutterworks\bhund\android\gradlew.bat" exited abnormally:
Command: D:\flutterworks\bhund\android\gradlew.bat app:properties
Please review your Gradle project setup in the android/ folder.
PS D:\flutterworks\bhund>
答案 0 :(得分:1)
我遇到了同样的问题,无法手动迁移到Androidx。 请注意,如果您想使用Firebase,则必须使项目现在位于Androidx中,否则以后可能会引起更多问题。
步骤1:在您的项目级别更改gradle:
classpath 'com.google.gms:google-services:4.3.2'
收件人:
classpath 'com.google.gms:google-services:3.2.0'
通常,在此步骤之后,您的项目将运行正常,但是可以立即导入到AndroidX,并且不会在使用Firebase时引起进一步的错误。
第2步:完成此操作后,只需使用Androidx设置创建一个新项目,就可以打开flutter_console.bat并导航到所需的文件夹,然后运行:
flutter create --androidx your_project_name
在抖动控制台上。
第3步:导航至新项目> android> gradle.properties,并检查其是否包含这两行:
android.useAndroidX=true
android.enableJetifier=true
这意味着该项目已迁移到Androidx。
第4步:最后,将您所有的代码从旧项目移至新的flutter项目,以及您可能已在旧项目中添加的所有依赖项和插件。 (包括步骤1中的依赖项)
答案 1 :(得分:0)
您可以尝试的是进入项目级别的构建,并按如下所示更改 classpath依赖项和 kotlin版本。
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
要在flutter项目中添加AndroidX,请转到 android程序包> gradle.properties
在gradle.properties内部添加两行。
android.useAndroidX=true
android.enableJetifier=true
这可能对您有用。