Skip to content

build: add support for generating Android release #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ build/
.gradle
local.properties
*.iml
android/gradle.properties

# node.js
#
Expand Down
11 changes: 11 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ android {
abiFilters "armeabi-v7a", "x86"
}
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
Copy link
Member

Choose a reason for hiding this comment

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

I actually used this approach when setting up a password for release. Not sure how we can have that flow integrated into this PR or even if we should as it's quite user specific 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

@housseindjirdeh that's the point, or something I do not understand. This is necessary to create its own release version (because for example it is not always enough for Android simulator, you need to check on a real device).

Copy link
Member

Choose a reason for hiding this comment

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

Sorry you may have missed the link (click here). So I don't store my password inside the gradle file and use keychain access instead. However, there's no real way to include that logic into the placeholder I think so I'm okay with having this as a placeholder to be honest.

keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
Expand All @@ -127,6 +137,7 @@ android {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
Expand Down
20 changes: 0 additions & 20 deletions android/gradle.properties

This file was deleted.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
"start:ios:logger": "LOGGER_ENABLED=true concurrently -r 'react-native start --reset-cache' 'yarn start:ios:no-packager'",
"start:ios:tron": "TRON_ENABLED=true concurrently -r 'react-native start --reset-cache' 'yarn start:ios:no-packager'",
"start:ios:no-packager": "react-native run-ios --no-packager",
"build:android:release": "cd android && ./gradlew assembleRelease",
"clean": "rm -rf node_modules",
"clean:android": "cd android && ./gradlew clean && cd -",
"link": "react-native link",
"ios": "react-native run-ios",
"android": "react-native run-android",
"android:release": "react-native run-android --variant=release",
"android:signkey": "cd android/app/ && keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000 && cd -",
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you should use an env var for the my-release-key.keystore keystore file 😃

Copy link
Member Author

Choose a reason for hiding this comment

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

@Antoine38660 did not quite understand how? Can you please explain?

Copy link
Member

@Antoine38660 Antoine38660 Aug 11, 2017

Choose a reason for hiding this comment

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

I mean, change the "android:signkey" script by something like:
"cd android/app/ && keytool -genkey -v -keystore RELEASE_KEYSTORE_PATH -alias ..."
where RELEASE_KEYSTORE_PATH is an environment variable that points to the keystore file.

But I checked the .gitignore file and every *.keystore are ignored so @housseindjirdeh can put it here without problem. Actually I think it is already in the repo in the android/keystore directory :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I do not know, it's recommended to generate it in the app/android folder, I can do it, but I do not see it necessary, because all the same, you need to manually specify the key in the android/gradle.properties file, including the MYAPP_RELEASE_STORE_FILE path, i.e. you can specify it.

Copy link
Member

@housseindjirdeh housseindjirdeh Aug 14, 2017

Choose a reason for hiding this comment

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

Yep so I generated the keystore file and it's currently living on my machine. It is being ignored in .gitignore and that's a good thing since we shouldn't be committing it in

If I'm not mistaken , android:signkey is for creating a new signing key correct? Not sure how or why we should pass in the keystore as a variable here 🤔 Or am I thinking wrong here @Antoine38660?

Copy link
Member Author

@lex111 lex111 Aug 14, 2017

Choose a reason for hiding this comment

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

I'll explain, this can be useful if you need to create a own release version of the application. Yes, you need to create a signature key, this command does this.

According to the manual, the key data must be placed in the android/gradle.properties.

@housseindjirdeh I really do not know how you release the new version on Google Play, this change does not hurt?

Copy link
Member

Choose a reason for hiding this comment

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

Nope I probably wouldn't need to run the command since I have a key but it simplifies the process. Was curious about what @Antoine38660 meant by adding an env variable but it should be good.

"commitmsg": "minicat $GIT_PARAMS | commitlint",
"precommit": "lint-staged",
"eslint": "eslint .",
Expand Down