我一直在 Android 应用程序中构建一个 Flutter 应用程序,一切正常,一旦我使用 GeoLocator 库,我的应用程序就崩溃了,说明它与 AndroidX 不兼容。当我尝试将我的代码迁移到 AndroidX 时,它说“您需要在模块 build.gradle 中将已编译的 SDK 设置为至少 28 才能迁移到 AndroidX。我已经将其设置为 28,但它仍然无法正常工作。
为了解决这个问题。我已经尝试了 Flutter 文档中提到的所有步骤。链接:https ://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
1. In android/gradle/wrapper/gradle-wrapper.properties change the line starting with distributionUrl like this:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
2. In android/build.gradle, replace:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
by
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
3. In android/gradle.properties, append
android.enableJetifier=true
android.useAndroidX=true
4.In android/app/build.gradle:
Under android {, make sure compileSdkVersion and targetSdkVersion are at least 28
5.Replace all deprecated libraries with the AndroidX equivalents. For instance, if you’re using the default .gradle files make the following changes:
In android/app/build.gradle
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
by
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Finally, under dependencies {, replace
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
by
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
这是我设置 SDK 版本的一些 build.grade 文件:
enter code here compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "co.appbrewery.clima"
minSdkVersion 28
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
尝试了上述所有方法,当我尝试将其设置为使用 Android Studio 功能迁移到 Android X 时,仍然会出现将您的 SDK 版本更改为至少 28 的错误。