Skip to content

Commit b371782

Browse files
authored
Merge pull request #3569 from StoDevX/print-gradle-version
Fix signed Gradle builds
2 parents 31ee3cf + a9c16d3 commit b371782

File tree

4 files changed

+53
-51
lines changed

4 files changed

+53
-51
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ jobs:
327327
command: ./scripts/should-skip-build && circleci step halt || echo "Build continuing."
328328
- run: node --version
329329
- run: yarn --version
330+
- run: cd android && ./gradlew --version
330331
- set-ruby-version
331332
- workspace-attach-node_modules
332333
- bundler-restore

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6767
- Fixed DatePicker by removing an unnecessary call to getDerivedStateFromProps (#3382)
6868
- Fixed the balances view from refreshing if the user has not agreed to the alert (#3509)
6969
- Fixed course search crash (#3564)
70+
- Building signed Android APKs was broken after RN 0.59; now it is fixed (#3569)
7071

7172
### Removed
7273
- Removed the `prepare` script patching `ScrollEnabled` inside `RCTMultilineTextInputView` (#3337)

android/app/build.gradle

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ def enableSeparateBuildPerCPUArchitecture = false
9797
*/
9898
def enableProguardInReleaseBuilds = false
9999

100+
/**
101+
* Fetch the keystore file's path from the environment
102+
*/
103+
String keystorePath = System.getenv("KEYSTORE_FILE")
104+
100105
android {
101106
compileSdkVersion rootProject.ext.compileSdkVersion
102107

@@ -122,8 +127,31 @@ android {
122127
}
123128

124129
signingConfigs {
125-
// the signingConfig is configured below
126-
release
130+
// originally derived from https://gist.github.com/gabrielemariotti/6856974
131+
if (keystorePath == null) {
132+
logger.warn "env['KEYSTORE_FILE'] not set"
133+
release
134+
return
135+
} else {
136+
logger.warn "env['KEYSTORE_FILE'] = ${keystorePath}"
137+
}
138+
139+
def propFile = new File(keystorePath)
140+
if (!propFile.canRead()) {
141+
logger.warn "${keystorePath} is not readable"
142+
release
143+
return
144+
}
145+
146+
def props = new Properties()
147+
props.load(new FileInputStream(propFile))
148+
149+
release {
150+
storeFile file(props['STORE_FILE'])
151+
storePassword props['STORE_PASSWORD']
152+
keyAlias props['KEY_ALIAS']
153+
keyPassword props['KEY_PASSWORD']
154+
}
127155
}
128156

129157
splits {
@@ -145,7 +173,9 @@ android {
145173

146174
minifyEnabled enableProguardInReleaseBuilds
147175
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
148-
signingConfig signingConfigs.release
176+
if (keystorePath != null) {
177+
signingConfig signingConfigs.release
178+
}
149179
}
150180
}
151181

@@ -186,41 +216,6 @@ android {
186216
}
187217
}
188218

189-
// borrowed from https://gist.github.com/gabrielemariotti/6856974
190-
def propFile = new File('android/app/signing.properties')
191-
if (propFile.canRead()) {
192-
Properties props = new Properties()
193-
props.load(new FileInputStream(propFile))
194-
195-
bool hasFile = props != null && props.containsKey('STORE_FILE');
196-
bool hasPassword = props != null && props.containsKey('STORE_PASSWORD');
197-
bool hasAlias = props != null && props.containsKey('KEY_ALIAS');
198-
bool hasKeyPass = props != null && props.containsKey('KEY_PASSWORD');
199-
200-
if (hasFile && hasPassword && hasAlias && hasKeyPass) {
201-
logger.info 'android/app/signing.properties is fully functional.'
202-
android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
203-
android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
204-
android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
205-
android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
206-
} else {
207-
println 'android/app/signing.properties found, but some entries are missing.'
208-
if (props == null) {
209-
logger.warn '`props` was null'
210-
} else {
211-
logger.warn "has STORE_FILE [y/n]: ${props.containsKey('STORE_FILE')}"
212-
logger.warn "has STORE_PASSWORD [y/n]: ${props.containsKey('STORE_PASSWORD')}"
213-
logger.warn "has KEY_ALIAS [y/n]: ${props.containsKey('KEY_ALIAS')}"
214-
logger.warn "has KEY_PASSWORD [y/n]: ${props.containsKey('KEY_PASSWORD')}"
215-
}
216-
android.buildTypes.release.signingConfig = null
217-
}
218-
} else {
219-
logger.warn 'android/app/signing.properties not found.'
220-
logger.warn "cwd: ${new File(".").absolutePath}"
221-
android.buildTypes.release.signingConfig = null
222-
}
223-
224219
dependencies {
225220
// please keep this list sorted
226221
implementation project(':bugsnag-react-native')

fastlane/platforms/android.rb

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,25 @@
7878
lane :matchesque do
7979
match_dir = clone_match
8080

81-
# don't forget --- lanes run inside of ./fastlane
82-
gradle_file = 'signing.properties'
83-
keystore_name = 'my-release-key.keystore'
84-
play_store_key = 'play-private-key.json'
85-
81+
# we'll be copying files out of the tempdir from the git-clone operation
8682
src = "#{match_dir}/android"
87-
88-
# FastlaneCore::CommandExecutor.execute(command: "pwd", print_all: true, print_command: true)
89-
UI.command "cp #{src}/#{gradle_file} ../android/app/#{gradle_file}"
90-
FileUtils.cp("#{src}/#{gradle_file}", "../android/app/#{gradle_file}")
91-
UI.command "cp #{src}/#{keystore_name} ../android/app/#{keystore_name}"
92-
FileUtils.cp("#{src}/#{keystore_name}", "../android/app/#{keystore_name}")
93-
UI.command "cp #{src}/#{play_store_key} ../fastlane/#{play_store_key}"
94-
FileUtils.cp("#{src}/#{play_store_key}", "../fastlane/#{play_store_key}")
83+
# don't forget: lanes run inside of ./fastlane, so we go up a level for our basedir
84+
dest = File.expand_path('..', '.')
85+
86+
# we export this variable so that Gradle knows where to find the .properties file
87+
signing_props_dest = "#{dest}/android/app/signing.properties"
88+
ENV['KEYSTORE_FILE'] = signing_props_dest
89+
90+
pairs = [
91+
{:from => "#{src}/signing.properties", :to => signing_props_dest},
92+
{:from => "#{src}/my-release-key.keystore", :to => "#{dest}/android/app/my-release-key.keystore"},
93+
{:from => "#{src}/play-private-key.json", :to => "#{dest}/fastlane/play-private-key.json"},
94+
]
95+
96+
pairs.each do |pair|
97+
UI.command "cp #{pair[:from]} #{pair[:to]}"
98+
FileUtils.cp(pair[:from], pair[:to])
99+
end
95100

96101
remove_match_clone(dir: match_dir)
97102
end

0 commit comments

Comments
 (0)