0

I have my android application (created in Android Studio) installed on my mobile device. I need to install another instance of this application (for testing on staging server, not production) with a few small fixes - such as url paths.

I know that two applications on a device cannot have the same java package, so what is the best way to solve it?

ukson
  • 125
  • 4
  • 10

1 Answers1

0

For use product flavors for this.

Each product flavor can have different applicationId:

android {
    …
    productFlavors {
        prod {
            applicationId "com.example.myapp"
        }
        stage {
            applicationId "com.example.myapp.stage"
        }
    }
}

Or you can add applicationIdSuffix to a flavor:

android {
    …
    defaultConfig {
        applicationId "com.example.myapp"
    }
    productFlavors {
        prod {
        }
        stage {
            applicationIdSuffix ".stage"
        }
    }
}

It's also useful if you want to be able to install both release and debug:

android {
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
    }
}

If you use it in both product flavor and build type, it will be chained, product flavor goes before build type. In this example suffix for fullDebug variant would be ".stage.debug".

Tomik
  • 23,857
  • 8
  • 121
  • 100