moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

Android fails to compile with AGP 7.3.0-beta03

Open headsvk opened this issue 3 years ago • 3 comments

Hi! I tried updating Android Gradle Plugin to 7.3.0-beta03 and Moko Resource to 0.20.1 and I can't compile Android anymore.

Steps:

  1. Install Android Studio Dolphin Beta 3
  2. Update Android Gradle Plugin in this project to 7.3.0-beta03 as in this fork
  3. Run sample.android-mpp-app

Gradle fails with:

Task :sample:android-mpp-app:compileDebugKotlinAndroid FAILED
e: ..\moko-resources\sample\android-mpp-app\build\generated\moko\androidMain\src\com\icerockdev\library\MR.kt: (16, 77): Unresolved reference: common_name

headsvk avatar Jun 20 '22 08:06 headsvk

I investigated this and it looks like AGP 7.3.0 is ignoring resources in the generated folder. It might be a bug in AGP but I don't know enough to create a ticket there.

headsvk avatar Jun 23 '22 12:06 headsvk

hi @headsvk as i see android gradle plugin read resources dirs before our generation dir was added. why - i not find yet. i think we should wait release version of AGP before own changes. for now you can add this to build.gradle:

android {
    sourceSets.getByName("main").res.srcDir(File(buildDir, "generated/moko/androidMain/res"))
}

Alex009 avatar Jul 10 '22 11:07 Alex009

I had a somehow similar issue. For me, assets were missing in builds; at first I blamed R8 aggressive mode, but it turned out to be this issue. I think it's safer to use this in general, until there's an update:

android {
    sourceSets["main"].apply {
        assets.srcDir(File(buildDir, "generated/moko/androidMain/assets"))
        res.srcDir(File(buildDir, "generated/moko/androidMain/res"))
    }
}

YektaDev avatar Jul 23 '22 08:07 YektaDev

Hey @Alex009, is your suggested fix still the way to go or could you investigate the problem further? AGP 7.3.0 is stable now.

ln-12 avatar Sep 26 '22 12:09 ln-12

It seems like AGP 8.0.0-alpha02 works without this workaround. Perhaps this is just a bug in AGP 7.3/7.4.

sproctor avatar Oct 06 '22 14:10 sproctor

@sproctor For me the problem persists with AGP 8.0.0-alpha08. It may be significant that in my case Moko is applied to an intermediate (hierarchical) source-set. However the workaround is still effective 👍

chris-hatton avatar Nov 21 '22 03:11 chris-hatton

will be released in 0.21.0

Alex009 avatar Mar 24 '23 11:03 Alex009