-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Using version code and version name for renaming generated packages with archivesBaseName #9
Comments
This is unfortunately not straightforward with the new Variant APIs in AGP 4.1+, where the focus is lazy task configuration. The following is a response from Xavier Ducrohet from the AGP team:
I put together the following custom task (based on the AGP recipe) to copy the raw APK to
If your build variant is Note that these APIs are all incubating so there might be easier ways to do it in the future. In the meantime adding this custom task to your Update: simplified task to do a simple copy instead of an artifact transform. |
How can I add the task above into my buildSrc file? To be specific |
This is the import:
Updated snippet above with all the imports required. |
Thanks @ychescale9 I see that If you already have such implementation in any of your projects here I'd appreciate if you could point me to it. Otherwise no worries I'll figure it out hopefully. |
This is a sample project that has AGP dependencies in |
Your sample helped me a lot plus some nice kotlin script tricks demonstrated in there however I just realized that What I ended up doing in order to rename my apk artifacts is simply translate an old groovy snippet into kotlin like so. import com.android.build.gradle.api.ApplicationVariant
import com.android.build.gradle.api.BaseVariantOutput
import com.android.build.gradle.internal.api.ApkVariantOutputImpl
// use the code below inside android{} block
applicationVariants.all(object : Action<ApplicationVariant> {
override fun execute(variant: ApplicationVariant) {
variant.outputs.all(object : Action<BaseVariantOutput> {
override fun execute(output: BaseVariantOutput) {
setVariantOutputName(output, variant)
}
})
}
})
fun setVariantOutputName(output: BaseVariantOutput, variant: ApplicationVariant) {
val outputVariant = (output as ApkVariantOutputImpl) // I just blindly copied this and it worked.
if (outputVariant.outputFileName.endsWith(".apk")) {
outputVariant.outputFileName =
"MyApp-" + variant.versionName + "-" + output.versionCode + ".apk"
}
} Most of the time I have no idea what I'm doing with gradle but this seemed to work in my case. |
This strategy is not anymore working on Giraffe? any other updated solution? thanks |
What's not working on Giraffe? AFAIK there's still no official way of renaming apk, so the gist above should work otherwise it would be a bug that we should report. |
This is how I did it in my new project for 2024:
|
I ran into same problem, and this solution worked for me! Thanks! |
In my project I need to rename the generated packages. Previously I have done it with following code in android defaultConfig block:
Now as I took the app-versioning plugin into use (actually the 0.4.0 version) I removed the versionCode and versionName definitions:
The problem is that the versionName and versionCode are now null and package name will be something like null-vcnull-release.apk
What might be best practice to rename the package when using the app-versioning plugin? Is there some way to get the versionName and versionCode from the app-versioning plugin in build.gradle during build?
The text was updated successfully, but these errors were encountered: