API 'BaseVariant.getApplicationIdTextResource' 已过时并已替换为 'VariantProperties.applicationId'
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'
构建 gradle 时,我收到此消息:
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'
我正在使用 Android Studio 4.1 Canary 10
和 gradle:4.1.0-alpha10
Navigation Safe Args plugin 似乎使用了 getApplicationIdTextResource()
,因此错误消息很可能是由于您使用了该插件引起的。
您想要加注 existing issue 以请求 Safe Args 插件使用新的替换 API。
Android Studio 4.1 提供以下信息,它将在 Android Gradle 插件的 5.0 版中删除。
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'.
It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see TBD.
To determine what is calling BaseVariant.getApplicationIdTextResource, use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
所以,我所做的是升级了所有 gradle 插件以及依赖版本,然后 运行,它对我有用
正如@ianhanniballake 所指出的,这似乎是由 Navigation Safe Args 插件引起的,请参阅 existing issue,也引用自他的回答。该问题已于 11 月 9 日标记为已修复。
在修复构建错误方面,将 Android Studio 从 4.1.0
升级到 4.1.1
为我修复了它。
几天我看到了同样的问题。然后我去->
build.gradle 文件
My Dependencies before update
检查依赖项
我将依赖项 google 服务更新到 4.3.4
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.google.gms:google-services:4.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
After update
现在工作正常。
待4.2.0稳定后解决
Android Gradle Plugin deprecated the getApplicationIdTextResource()
API on the class BaseVariant in version 4.1.0 (see bug). The
replacement API (onVariantProperties) did not work properly for
feature libraries, so to avoid the deprecation warning, reflection was
used. That is only a short term solution, and when AGP 4.2.0 is stable
we should update to that version and remove the reflection immediately
因此,如果您需要 Safe Args 而不需要 Gradle 的最新功能,请将 Gradle 版本保留在 Android Gradle 插件版本 3.6.4。一旦稳定版 4.2.0 发布,更新到最新版本。
对我来说,这是因为 IDE Kotlin 插件和 project_name/build.gradle 文件
之间的 Kotlin 版本不同
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
"Kotlin version that is used for building with Gradle (1.3.72) differs from the one bundled into the IDE plugin (1.4.31) "
一旦我成功了,它又开始编译了。
按照描述更改为 androidx.navigation:navigation-*:2.4.0-alpha02 here 允许在 Arctic Fox 下构建我的应用程序而不会收到 getApplicationIdTestResource 警告
来自应用程序 build.gradle 文件:
def nav_version = "2.4.0-alpha02"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
并且在 build.gradle 文件中:
def nav_version = "2.4.0-alpha02"
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
从项目中删除 .idea 和 .gradle 文件.. 它与我一起工作
这个错误是 NavigationComponent
我在 Android Studio Cannery 13 中遇到的。
所以我将 nav_version 改成了这个,我的问题就解决了。
ext {
*************** nav_version = "2.4.0-alpha10" ************
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-alpha13'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
并在 应用程序模块中 build.gradle:
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
我遇到了同样的问题,解决方法如下:
所以我去 -> build.gradle 文件
升级前我的依赖项
检查依赖关系
我将 Google 服务依赖更新到最新版本
dependencies {
classpath 'com.android.tools.build:gradle:(latest version)'
classpath 'com.google.gms:google-services:(latest version)'
}
这个错误发生在我更新kotlin版本到1.7之后。
这是 Android Studio
中的 NavigationComponent
所以我将 nav_version 更改为此,我的问题已解决:“2.4.0-beta02”
// Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:2.4.0-beta02"
implementation "androidx.navigation:navigation-ui-ktx:2.4.0-beta02"
在我的例子中,我使用的是 navigation-fragment 的 2.3.1 版本。
我刚刚将它更新到 2.4.2,它对我很有帮助
构建 gradle 时,我收到此消息:
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'
我正在使用 Android Studio 4.1 Canary 10
和 gradle:4.1.0-alpha10
Navigation Safe Args plugin 似乎使用了 getApplicationIdTextResource()
,因此错误消息很可能是由于您使用了该插件引起的。
您想要加注 existing issue 以请求 Safe Args 插件使用新的替换 API。
Android Studio 4.1 提供以下信息,它将在 Android Gradle 插件的 5.0 版中删除。
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'. It will be removed in version 5.0 of the Android Gradle plugin. For more information, see TBD. To determine what is calling BaseVariant.getApplicationIdTextResource, use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
所以,我所做的是升级了所有 gradle 插件以及依赖版本,然后 运行,它对我有用
正如@ianhanniballake 所指出的,这似乎是由 Navigation Safe Args 插件引起的,请参阅 existing issue,也引用自他的回答。该问题已于 11 月 9 日标记为已修复。
在修复构建错误方面,将 Android Studio 从 4.1.0
升级到 4.1.1
为我修复了它。
几天我看到了同样的问题。然后我去-> build.gradle 文件
My Dependencies before update
检查依赖项
我将依赖项 google 服务更新到 4.3.4
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.google.gms:google-services:4.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
After update
现在工作正常。
待4.2.0稳定后解决
Android Gradle Plugin deprecated the getApplicationIdTextResource() API on the class BaseVariant in version 4.1.0 (see bug). The replacement API (onVariantProperties) did not work properly for feature libraries, so to avoid the deprecation warning, reflection was used. That is only a short term solution, and when AGP 4.2.0 is stable we should update to that version and remove the reflection immediately
因此,如果您需要 Safe Args 而不需要 Gradle 的最新功能,请将 Gradle 版本保留在 Android Gradle 插件版本 3.6.4。一旦稳定版 4.2.0 发布,更新到最新版本。
对我来说,这是因为 IDE Kotlin 插件和 project_name/build.gradle 文件
之间的 Kotlin 版本不同classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
"Kotlin version that is used for building with Gradle (1.3.72) differs from the one bundled into the IDE plugin (1.4.31) "
一旦我成功了,它又开始编译了。
按照描述更改为 androidx.navigation:navigation-*:2.4.0-alpha02 here 允许在 Arctic Fox 下构建我的应用程序而不会收到 getApplicationIdTestResource 警告
来自应用程序 build.gradle 文件:
def nav_version = "2.4.0-alpha02"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
并且在 build.gradle 文件中:
def nav_version = "2.4.0-alpha02"
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
从项目中删除 .idea 和 .gradle 文件.. 它与我一起工作
这个错误是 NavigationComponent
我在 Android Studio Cannery 13 中遇到的。
所以我将 nav_version 改成了这个,我的问题就解决了。
ext {
*************** nav_version = "2.4.0-alpha10" ************
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-alpha13'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
并在 应用程序模块中 build.gradle:
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
我遇到了同样的问题,解决方法如下: 所以我去 -> build.gradle 文件
升级前我的依赖项
检查依赖关系
我将 Google 服务依赖更新到最新版本
dependencies {
classpath 'com.android.tools.build:gradle:(latest version)'
classpath 'com.google.gms:google-services:(latest version)'
}
这个错误发生在我更新kotlin版本到1.7之后。 这是 Android Studio
中的 NavigationComponent所以我将 nav_version 更改为此,我的问题已解决:“2.4.0-beta02”
// Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:2.4.0-beta02"
implementation "androidx.navigation:navigation-ui-ktx:2.4.0-beta02"
在我的例子中,我使用的是 navigation-fragment 的 2.3.1 版本。 我刚刚将它更新到 2.4.2,它对我很有帮助