Skip to content

Conversation

@khacanh
Copy link

@khacanh khacanh commented Mar 1, 2017

I use the productFlavor and buildType in the variant option to get the path to BuildConfig.java. From there I parse the APPLICATION_ID for that build variant.

We can also define and run a gradle task to generate applicationId, but it is not so nice.

I have to change the code quite a bit as it has to run after BuildConfig.java is generated (via build apk task)

Test plan (required)

  1. Configure build.gradle
    signingConfigs {
        production {
            keyAlias = "release"
            storeFile = file("../keystores/release.jks")
            keyPassword = "******"
            storePassword = "******"
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
        }
        production {
            applicationIdSuffix ".production"
            versionNameSuffix ""
            signingConfig signingConfigs.production
        }
    }

    productFlavors {
        demo {
            applicationIdSuffix ".demo"
        }

        full {
            applicationIdSuffix ".full"
        }
    }
  1. Run react-native run-android --variant DemoDebug

- Eg `react-native run-android --variant DemoDebug --applicationId com.android.dem.debug`
@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Mar 1, 2017
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

khacanh added 2 commits March 4, 2017 16:11
…-android

- Get the path to BuildConfig.java from variant and parse the APPLICATION_ID
- Remove applicationId option
@khacanh
Copy link
Author

khacanh commented Mar 4, 2017

Ok, so I change the PR a bit. We don't really need the applicationId option as we can get it from the variant.

I use the productFlavor and buildType in the variant option to get the path to BuildConfig.java. From there I parse the APPLICATION_ID for that build variant.

We can also define and run a gradle task to generate applicationId, but it is not so nice.

I have to change the code quite a bit as it has to run after BuildConfig.java is generated (via build apk task)

@khacanh khacanh changed the title Support run-android with applicationId options Fix activity path in run-android launch command with multiple build variants Mar 4, 2017
const productFlavor = variantKeys[0], buildType = variantKeys[1];
const packagePath = packageName.replace('.', '/');
const applicationId = fs.readFileSync(
`app/build/generated/source/buildConfig/${productFlavor}/${buildType}/${packagePath}/BuildConfig.java`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

productFlavor is not a compulsory field so it may or may not exist. In cases where it doesn't the path to the BuildConfig.java file will be malformed. Eg: (app/build/generated/source/buildConfig//debug/com/example/BuildConfig.java)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if I dont have any flavors, then there is no right way to differentiate between whether the value in the variant flag is a flavor or a build type. I think a better way would be to add another flag or follow the implementation in #12820

@facebook-github-bot
Copy link
Contributor

@khacanh I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project.

@SuhairZain
Copy link
Contributor

Hi @khacanh,
I'm having the issue where run-android command is unable to find the MainActivity to open by default. However, I'm not using productFlavors, but the buildTypes. Will this PR fix that issue as well?

@mataiaslev
Copy link

i am in the same situation @SuhairZain

@stale
Copy link

stale bot commented Nov 19, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 19, 2017
@stale stale bot closed this Nov 26, 2017
@johanforssell
Copy link

I'm writing new versions of old apps, and thus I have inherited old app id's.

My code have the package com.common.package (in source files and AndroidManifest.xml).

My build.gradle contains

    buildTypes {
        debug {
        }
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

    flavorDimensions "appName"
    productFlavors {
        appAAA {
            dimension "appName"
            applicationId "com.AAA.app"
            versionCode 100
            versionName "3.0.0"
        }
        appBBB {
            dimension "appName"
            applicationId "com.BBB.app"
            versionCode 100
            versionName '3.0.0'
        }
    }

First the app can be installed with gradlew

cd android && ./gradlew installAppBBBDebug

The I can start it manually with

adb -s emulator-5554 shell am start -n com.BBB.app/com.common.package.MainActivity

This is a bloody hassle. I would rather not have to mess with it like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Stale There has been a lack of activity on this issue and it may be closed soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants