121

When building gradle I'm getting this message:

API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'

I'm using Android Studio 4.1 Canary 10 and gradle:4.1.0-alpha10

1
  • happened for me but for 'RecyclerView'
    – The MJ
    Oct 20, 2021 at 21:11

13 Answers 13

134

It seems like the Navigation Safe Args plugin uses getApplicationIdTextResource(), so it is most likely that the error message is caused by your usage of that plugin.

You'd want to star the existing issue to ask the Safe Args plugin to use the new replacement API.

7
  • 10
    UPDATE: According to this comment, it's been fixed in Android Studio 4.2 Beta 2.
    – Alther
    Jan 29, 2021 at 23:14
  • 40
    and if you're using arctic fox, you're still doomed :|
    – Luke
    May 19, 2021 at 17:35
  • 4
    2.4.0-alpha02 fixed the issue, works on arctic fox too (latest: alpha06)
    – norbDEV
    Aug 11, 2021 at 12:41
  • Latest alpha 2.4.x-alphaXX seems to fix with artic fox as @norbDEV mentioned.
    – FraK
    Aug 22, 2021 at 19:16
  • 1
    over a year for google to fix this things Oct 11, 2021 at 18:13
37

Changing to androidx.navigation:navigation-*:2.4.0-alpha02 as described here allowed a build of my app under Arctic Fox without getting the getApplicationIdTestResource warning

From the application build.gradle file:

def nav_version = "2.4.0-alpha02"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"

And in the build.gradle file:

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"
1
  • This is the best answer, as it is the most up to date. Should be closer to the top. Correct answer should be a combination of this and the current correct answer. Aug 23, 2021 at 20:35
9

few days i see the same issue. Then i go to -> build.gradle file

My Dependencies before update

check the dependencies

I update the dependencies google services to 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

Now its working fine.

2
6

This error was for NavigationComponent for me in Android Studio Cannery 13.

So I changed the nav_version to this and My issue was solved.

 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"

and in app module build.gradle:

   implementation "androidx.navigation:navigation-fragment:$nav_version"
    implementation "androidx.navigation:navigation-ui:$nav_version"
    androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
2
  • 1
    Thank you very much, I can not believe that the build is working again! Tried a lot of solutions, and none worked. I just want to update my android project from java 8 to java 11, and it's just not building ... Thank you! Oct 19, 2021 at 15:44
  • This worked for me as well. 2.3.1 -> 2.4.2
    – sud007
    Apr 12, 2022 at 12:32
5

It will be solved, when 4.2.0 is stable.

From the existing issue:

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

So if you need Safe Args and do not need latest features of Gradle, keep Gradle version in Android Gradle Plugin version at 3.6.4. Once stable 4.2.0 released, update to the latest.

1
  • updated with 4.2.0 warning fixed
    – sud007
    Apr 12, 2022 at 12:32
3

This error happened after i updated kotlin version to 1.7. this was for NavigationComponent in Android Studio

So I changed the nav_version to this and My issue was solved : "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"
2

For me it was because of different Kotlin versions between IDE Kotlin plugin and project_name/build.gradle file

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) "

Once I made it even it started to compile again.

2

In my case I was using 2.3.1 version of navigation-fragment. I just updated it to 2.4.2 and it's helped me

1

So, What i have done is that I have upgraded all the gradle plugins as well as dependecies versions and then run, It worked for me

1

I had the same problem and it was solved like this: So I go to -> build.gradle file

My dependencies before upgrade

check the dependencies

I update Google services dependencies to latest version

dependencies {
 classpath 'com.android.tools.build:gradle:(latest version)'
 classpath 'com.google.gms:google-services:(latest version)'

}
0

Android Studio 4.1 giving the following information and It will be removed in version 5.0 of Android Gradle Plugin.

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.

0

As @ianhanniballake has pointed out, it seems likely that it's caused by the Navigation Safe Args plugin, see the existing issue, also referenced from his answer. The issue was marked as fixed on 9 November.

In terms of fixing the build error, upgrading Android Studio from 4.1.0 to 4.1.1 fixed it for me.

3
  • 14
    Upgrading to 4.1.1 didin't fix the issue for me.
    – ShadeToD
    Nov 12, 2020 at 10:31
  • 1
    @ShadeToD I don't see it as a build error any more, just as a warning, as outlined in the existing issue in the tracker. Are you still seeing it as an error? Nov 19, 2020 at 11:52
  • upgrading to 4.2.0 did fix it.
    – sud007
    Apr 12, 2022 at 12:33
0

delete the .idea and .gradle files from the project .. it worked with me

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.