Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle build : renaming the apk

How can I adapt my build.gradle to change the final basename of the apk(s) ? (without changing the default suffixes)

like image 393
ben75 Avatar asked May 28 '13 08:05

ben75


People also ask

How do I rename an apk file?

Navigate to the folder in which your apk is present. In that folder select your APK file. Right-click on it and click on rename option to rename your APK file.

Can I rename app debug apk?

If anyone is looking to change apk name outside the Android studio(just to send this file to someone else, as in my case), just right click the app name and change it to whatever you want.

Does Gradle handles installing your app on a device?

Gradle is an automated build system used by Android Studio to build your apps. Gradle handles installing your app on a device.

What is Android Gradle build?

The Android Gradle plugin (AGP) is the official build system for Android applications. It includes support for compiling many different types of sources and linking them together into an application that you can run on a physical Android device or an emulator.


3 Answers

On Gradle 1.8, project.archivesBaseName does work, but it gives this complaint:

Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties. Deprecated dynamic property: "archivesBaseName" on "root project 'myapp'", value: "AnotherName".

To get rid of the warning (and to avoid your build breaking on Gradle 2.0), use this:

project.ext.set("archivesBaseName", "AnotherName");

...as suggested in the ExtraPropertiesExtension documentation.

Update (Gradle plugin 1.1.0)

Android Gradle plugin version 1.1.0 introduced a bug which broke archivesBaseName, as friederbluemle noted. But fortunately this has since been fixed (in version 1.1.2).

like image 74
Jonik Avatar answered Oct 20 '22 05:10

Jonik


I found a very simple solution. The apk base name is the property archivesBaseName defined on the project. So the following line is enough to rename the apks:

project.archivesBaseName = "AnotherName";
like image 27
ben75 Avatar answered Oct 20 '22 05:10

ben75


Starting with version 1.1.0 of the Android Gradle plugin you have to use

archivesBaseName = "yourOtherName"

instead of project.ext.set("archivesBaseName", "yourOtherName") in your build.gradle to make it work.

like image 40
Fabian Frank Avatar answered Oct 20 '22 06:10

Fabian Frank