11

I want to use 2 productFlavors for my Android App: live and staging.

In app/build.grandle I defined them like this:

defaultConfig {
    applicationId "com.some.id"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
}
splits {...}
buildTypes {
    release {
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
    debug {
        debuggable true
        minifyEnabled false
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }

    productFlavors {
        live {
            applicationId "com.some.id"
        }
        staging {
            applicationId "com.some.id.staging"
        }
    }
}

Now when I run react-native run-android --variant=liveDebug everything works just fine but when I try to run react-native run-android --variant=stagingDebug i get the error:

Installed on 1 device.

BUILD SUCCESSFUL

Total time: 11.824 secs
Starting the app on 192.168.56.101:5555 (/usr/local/opt/android-sdk/platform-tools/adb -s 192.168.56.101:5555 shell am start -n com.somepackage/.MainActivity)...
Starting: Intent { cmp=com.somepackage/.MainActivity }
Error type 3
Error: Activity class {com.somepackage/com.somepackage.MainActivity} does not exist.

As the output says, the App was installed on the device but why does it say that MainActivity does not exist ? I guess it is due to the different applicationId although it is correct according to this guide

How can I solve this?

Thanks in advance!

Vic Torious
  • 1,093
  • 1
  • 16
  • 23

6 Answers6

14

I had the same issue and I solve by adding the appIdSuffix to the react-native run command.

react-native run-android --variant variantDebug --appIdSuffix suffix
BlaShadow
  • 8,375
  • 7
  • 32
  • 58
3

Add the --appId on run command, so the react native will know where to find the Main Activity:

react-native run-android --variant=stagingDebug --appId com.some.id.staging

João Baraky
  • 141
  • 7
  • for some reason, this doesn't work for me. I have an `applicationId` inside each `productFlavors`. It tries to start the activity of the wrong app id `react-native-cli: 2.0.1 - react-native: 0.59.8 - ` – Gianfranco P. May 29 '19 at 08:51
2

Uninstall the app from the device using:

cd android && ./gradlew uninstallAll

Then run the app again using:

react-native start
react-native run-android
Princewill Iroka
  • 221
  • 1
  • 4
  • 11
1

There is a pull request pending for React Native that will fix this issue.

Until then you can simply replace /node_modules/react-native/local-cli/runAndroid/runAndroid.js with the runAndroid.js file from the pull request.

oldwizard
  • 4,677
  • 2
  • 28
  • 29
0

Try giving resValue like this:

staging { applicationId "com.some.id.staging" resValue "string", "build_config_package", "com.some.id" }

Pavan Mallela
  • 521
  • 3
  • 3
0

Cause you change the applicationId in the productFlavors, react-native-cli can't recognize it. To fix, just add your changed appId when run start command

react-native run-android --variant=staging --appId com.some.id.staging
tuan.tran
  • 1,548
  • 12
  • 19