After upgrading to Android Studio Artic Fox and AGP 7.0.0, custom views no longer render in Layout Preview

Viewed 568

After upgrading to Android Studio Artic Fox. EVERY SINGLE ONE of my Custom Views do not render in the layout preview. Is there a known workaround right now for this problem? My app compiles perfectly fine, and functions exactly as before the Artic Fox update. Actually, I haven't even changed the project settings or source code besides updating to Artic Fox. And now all of my custom views do not render anymore.

I have backups of different version of my app. I create a copy of the older version and open them in Artic Fox. And still, these older version don't have previewable custom views either! It turns out that after a rebuild on the older backups, my custom Views will render perfectly fine in the layout preview. Therefore, the problem is probably related to my specific project configuration.

I tried downgrading gradle 7.0.0 back to 4.2.0 and invalidating the cache and restarting. It did not fix it.

I get this warning for every single custom view:

Missing Class:

The following classes could not be found

com.poetryrocksalot.dummyproject.widget1 (Fix Build Path, Edit XML, Create Class)
com.poetryrocksalot.dummyproject.widget2 (Fix Build Path, Edit XML, Create Class)
com.poetryrocksalot.dummyproject.widget3 (Fix Build Path, Edit XML, Create Class)
com.poetryrocksalot.dummyproject.widget4 (Fix Build Path, Edit XML, Create Class)
com.poetryrocksalot.dummyproject.widget5 (Fix Build Path, Edit XML, Create Class)
com.poetryrocksalot.dummyproject.widget6 (Fix Build Path, Edit XML, Create Class)
com.poetryrocksalot.dummyproject.widget7 (Fix Build Path, Edit XML, Create Class)

etc...
1 Answers

I eventually got it working on Android Studio 4.2.2. I did several things, but I don't know if all of the steps besides the last one were necessary.

Chronologically, I did the following:

  1. I installed Android Studio 4.2.2 but this did not fix the issue.

  2. I went into one of my older backups and reverted to the Gradle version of that backup. I made the changes in build.gradle (project). This still did not fix the issue.

  3. I went into the file "gradle-wrapper.properties" and downgraded the distributionURL gradle bin version (I just used the last version from the same backup). And this finally fixed it for me.

Before (build.gradle project)

    buildscript {
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:7.0.0'
        }
    }

After

    buildscript {
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:4.2.1'
        }
    }

Before (gradle-wrapper.properties)

distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip

After

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip

I have no idea why this fixes the layout previewing problems and the "Missing Classes" warning. I am curious to understand this problem. So if you encountered this problem and my steps fixed it for you, please comment.

Update 1: I had another instance of the same project. And in that one I downgraded Gradle to 4.2.1 but the distributionUrl stayed at 7.0.2 and the Custom Views showed up just fine on Android Studio 4.2.2. Tell me which steps worked for you.

Update 2: Updated to Artic Fox and upgrade Gradle in both steps. And problem does not happen anymore. If the problem isn't related to Gradle or Android Studio, I have no idea what is going on. I did do a reinstall of Artic Fox. Maybe that was the only fix necessary. Maybe I'm running Gradle through a CDN and they just pushed silently a patch to Gradle or something. But 7.0.0 works now along with Artic Fox.

Update 3: Upgraded to Gradle 7.0.0 again and the custom Views broke again.

Update 4: I suspect it has nothing to do with the Gradle version now. If you want to update Gradle. Do it manually, specify the Gradle versions by typing in the numbers and clicking on the sync button. If you are using Artic Fox, DO NOT click on the update Gradle message when you get that notification. This will screw up your project and your custom Views will not render. I just recently tested random custom Views on Github, and they do NOT render properly because of the update assistant. TLDR: DO NOT USE UPDATE ASSISTANT TO UPGRADE GRADLE.

Related