Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use moko-resources without Android Gradle Plugin #260

Closed
r4zzz4k opened this issue Nov 20, 2021 · 2 comments · Fixed by #262
Closed

Unable to use moko-resources without Android Gradle Plugin #260

r4zzz4k opened this issue Nov 20, 2021 · 2 comments · Fixed by #262
Assignees
Labels
bug Something isn't working
Milestone

Comments

@r4zzz4k
Copy link

r4zzz4k commented Nov 20, 2021

I know that this is not a very important flow for you, but I like the plugin and tend to use it in all multiplatform-related pet projects.

I tried to create the project where there is no need for Android app, so I did not apply any Android plugins, and there were multiple issues with this setup.

  1. (actually covered by Can't use plugin without Android Gradle Plugin (clean Compose for Desktop usage) #252) One has to add AGP to buildscript classpath in any case. If you don't, you get the following:
FAILURE: Build failed with an exception.

* Where:
Build file '[...]/common/build.gradle.kts' line: 3

* What went wrong:
An exception occurred applying plugin request [id: 'dev.icerock.mobile.multiplatform-resources']
> Failed to apply plugin 'dev.icerock.mobile.multiplatform-resources'.
   > Could not create plugin of type 'MultiplatformResourcesPlugin'.
      > Could not generate a decorated class for type MultiplatformResourcesPlugin.
         > com/android/build/gradle/BaseExtension

Unfortunately since BaseExtension isn't in gradle-api part of AGP, nothing can be done with this, apart from maybe mentioning that you have to add com.android.tools.build:gradle to your buildscript classpath even if you don't do Android.

  1. The module where the generation is happening still needs Android plugin applied.

Without the plugin, I don't even see the Moko-resources tasks section of ./gradlew :common:tasks, so they don't get registered.

Also, as soon as you add Android plugin to the project, Kotlin Multiplatform plugin starts requiring android() target, as it crashes when resolving jvmCompileClasspath without the target.

I don't know how much do you depend on AGP for your resource generation part, but it would be nice to be able to generate resources when Android plugin is not present (of course skipping Android-related generation altogether).

Obvious workaround is to add

  • common/build.gradle.kts
plugins {
    id("com.android.library")
}

android { compileSdk = 31 }

kotlin {
	android()
}
  • common/main/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.example.common"/>

After these additions, everything starts working as intended.

Fortunately, my desktop module (which uses JVM Kotlin plugin, not multiplatform one) doesn't require Android plugin applied. Either moko-resources doesn't require Android plugin when there are no resources to be generated (though I believe the plugin is still needed to consume resources from dependency), or moko-resources doesn't require Android plugin when Kotlin JVM plugin is used instead of Kotlin Multiplatform one (I didn't check that).

So to sum up everything above, is there a chance that dependency on AGP for resource generation can become optional?

@r4zzz4k
Copy link
Author

r4zzz4k commented Nov 20, 2021

Oh shoot, sorry, it's partially covered by #252, my bad. In this case disregard the first question in my issue.

@Alex009 Alex009 linked a pull request Dec 4, 2021 that will close this issue
@Alex009 Alex009 added this to the 0.17.3 milestone Dec 4, 2021
@Alex009 Alex009 self-assigned this Dec 4, 2021
@Alex009 Alex009 added the bug Something isn't working label Dec 4, 2021
@Alex009
Copy link
Member

Alex009 commented Dec 4, 2021

start from 0.17.3 you can use moko-resources without android gradle plugin. but you still should use kotlin multiplatform plugin

@Alex009 Alex009 closed this as completed Dec 4, 2021
illarionov added a commit to illarionov/moko-resources that referenced this issue Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants