• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Cannot rebuild after changing targetSdkVersion

writerman

Newbie
I have a legacy app and no desire to update it but Google Play told me I have to increase my targetSdkVersion to at least 31. After some experimentation, I changed it to 32.

I now get three red lines in my build.gradle:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'

Hovering on one of these, it told me I needed to upgrade to AndroidX, which I did by choosing Refractor>Migrate to AndroidX... It did some stuff, don't know what. The red lines are still there. If I try to rebuild, I get fifteen errors in values.xml saying "Android resource linking failed" on lines starting:
<declare-styleable name="Constraint"><attr name="android:orientation"/>...

I have upgraded Android Studio to the latest version. Any suggestions what to try next? I find it enormously frustrating that a) I am forced to change my target SDK for an app that hasn't changed in three years and b) when I do, it seems to open a great can of worms and I'm beginning to panic that I will never get this app to compile again.

I have decades of experience as a developer but I don't really understand gradles and stuff. I just want to write some Java and turn it into an app. I seem to end up fighting the developer tools all the way.
 
I understand how frustrating it can be to deal with issues like these, especially when you're trying to maintain a legacy app.

Regarding the red lines in your build.gradle file, it looks like you are using version 28 of the Android Support Libraries, which is no longer supported. The latest version of the Support Libraries is 29.0.0, but it is recommended that you migrate to AndroidX, which is a refactored version of the Support Libraries.

To migrate to AndroidX, you can use the "Refactor > Migrate to AndroidX..." option in Android Studio, as you mentioned. This will update your app's dependencies and package names to use AndroidX artifacts. However, it looks like there may have been some issues with the migration in your case.

One thing you can try is to clean and rebuild your project after migrating to AndroidX. In Android Studio, you can do this by going to "Build > Clean Project" and then "Build > Rebuild Project". This will delete the build artifacts and re-create them, which may help resolve any issues that were introduced during the migration.

You may also want to check your values.xml file for any errors that may have been introduced during the migration. It looks like you are seeing "Android resource linking failed" errors, which can occur if there are issues with the resource values or if the resources cannot be found.

If cleaning and rebuilding the project and checking for errors in your values.xml file does not resolve the issues, you may need to carefully review the changes that were made during the migration to AndroidX and try to identify any issues that may have been introduced.
 
Many thanks for your helpful response. After much experimentation, I discovered a message suggesting there was an Android Gradle Plugin update avaiable (I thought I'd done that, but maybe not). After upgrading to APG 4.2.2, I was able to get my project to build (after fixing a couple of other minor errors on the way).
I now have a load of "deprecated" messages but I can look into those in due course.
Thanks again for your help.
 
Many thanks for your helpful response. After much experimentation, I discovered a message suggesting there was an Android Gradle Plugin update avaiable (I thought I'd done that, but maybe not). After upgrading to APG 4.2.2, I was able to get my project to build (after fixing a couple of other minor errors on the way).
I now have a load of "deprecated" messages but I can look into those in due course.
Thanks again for your help.

You Welcome
 
Back
Top Bottom