How change package name with help Bitrise?

Hello.

I designed the android app, and now I want to generate an apk.
And as far as I know with help Bitrise can be changed package name of my application, is this possible?
And if so, how?

Thanks.

Hi,

May I ask why do you want to change the package name on bitrise.io? In general you should do that in your Android project config.

Of course, as usual, anything you can run in your terminal can be automated on bitrise.io too, but that might require quite a bit of scripting.

At the moment I can not use Android Studio, and I have access to all application data only with bitbucket and bitrise. For this I want to try to change package name from Bitrise.

Could you tell me where I can find information on how to do this, or if it’s not hard for you, tell me exactly how I can do this?

Thanks.

There are many solutions, from the top of my head, if you have access to the repository:

  1. Locate the file the package id/name (or any info you’re looking for to change) is stored in
  2. Get its relative path, relative to the repository root, e.g. ./sub/dir/file.ext
  3. On bitrise, using the Script step, either modify the file (e.g. with sed or similar) OR overwrite the file

E.g. if you have write access to the repository, copy the file ./sub/dir/file.ext to ./sub/dir/modified-file.ext, and of course modify anything in it what you want to; then you can during the build simply replace that file with a Script step:

#!/bin/bash
set -ex

cp "./sub/dir/modified-file.ext" "./sub/dir/file.ext"

This will replace ./sub/dir/file.ext with the ./sub/dir/modified-file.ext. Do this right after the Git Clone step.

There are of course other solutions like:

  1. Using the Generic File Storage to store the modified file (http://devcenter.bitrise.io/tutorials/how-to-use-the-generic-file-storage/)
  2. Instead of replacing the file with another one in the Script you could modify the file with grep, awk, sed, …
  3. Use a Step like Change value in file or Generate Text File (community created steps)

And probably at least a dozen other solutions - which one is best for you depends on your project and workflow, how you want to maintain this configuration :slight_smile:

In my case, to change the package name, I need to change the package paths in all classes of my application.
That is, I will need to replace each class with a class with new data (a new package name)?

That shouldn’t be required. The package name of the generated app (APK) does not depends on what package paths you use in your code. By default it should be a simple config in the build.gradle config file + in AndroidManifest.xml (设置应用 ID  |  Android 开发者  |  Android Developers).

It seems simple. That is, if I understood you correctly, I need to use the script to modify the build.gradle config file and AndroidManifest.xml ? And this I can do with the parameter sed?

sed is not a parameter, that’s a unix command line tool which you can use in a Script (https://www.gnu.org/software/sed/manual/sed.txt)

If you’re not familiar with scripting I’d suggest you to rather use a step (like the Change value in file one), or just modify the file and do a simple copy/move like I described here: How change package name with help Bitrise? - #4 by viktorbenei

I’d also suggest you to check this guide, to see how you can experiment with your config on your Mac / Linux machine:

I frequently use sed to update values at build time, like API keys, etc.

#!/bin/bash
 
sed -i '' "s/[the placeholder value in my target file]/$[some Bitrise variable]/g" "path/to/MyTargetFile.ext"

(without the square brackets, of course)

So, for example, if I’m injecting a Raygun API key:

sed -i '' "s/RAYGUN_API_KEY/$RAYGUN_API_KEY/g" "MyPath/APIKeys.cs"

I have A $RAYGUN_API_KEY env variable in my Bitrise workflow, and a placeholder value of “RAYGUN_API_KEY” in my APIKeys.cs. You can of course use whatever variable and placeholder you want, but I try make them match so that they’re easier to manage when I have a ton of them. (mind the $ sign!)

I like to host my bash scripts on gist.github.com (because it’s dead simple) and then use the Remote Bash Script Runner step in Bitrise to reference them. Make sure to use the raw URL that Gist gives you. And note that every time you update a Gist, the raw URL changes.

1 Like

Thanks for the notes/tips @jsauve!

Ohh, I didn’t know about this, TIL :smiley: