Skip to content

Commit 11865cd

Browse files
committed
add signing config to gradle build
1 parent 089daac commit 11865cd

13 files changed

+138
-32
lines changed

mode/src/processing/mode/android/AndroidBuild.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public boolean usesOpenGL() {
181181

182182

183183
public String getPathForAPK() {
184-
String suffix = target.equals("release") ? "release_unsigned" : "debug";
184+
String suffix = target.equals("release") ? "release" : "debug";
185185
String apkName = getPathToAPK() + sketch.getName().toLowerCase() + "_" + suffix + ".apk";
186186
final File apkFile = new File(tmpFolder, apkName);
187187
if (!apkFile.exists()) {
@@ -196,9 +196,9 @@ public String getPathForAPK() {
196196
* @throws SketchException
197197
* @throws IOException
198198
*/
199-
public File buildBundle(String target) throws IOException, SketchException {
199+
public File buildBundle(String target, String password) throws IOException, SketchException {
200200
this.target = target;
201-
File folder = createProject(true);
201+
File folder = createProject(true, password);
202202
if (folder == null) return null;
203203
if (!gradleBuildBundle()) return null;
204204
return folder;
@@ -211,9 +211,9 @@ public File buildBundle(String target) throws IOException, SketchException {
211211
* @throws SketchException
212212
* @throws IOException
213213
*/
214-
public File build(String target) throws IOException, SketchException {
214+
public File build(String target, String password) throws IOException, SketchException {
215215
this.target = target;
216-
File folder = createProject(true);
216+
File folder = createProject(true, password);
217217
if (folder == null) return null;
218218
if (!gradleBuild()) return null;
219219
return folder;
@@ -225,7 +225,7 @@ public File build(String target) throws IOException, SketchException {
225225
* sketch. Creates the top and app modules in the case of regular, VR, AR and
226226
* wallpapers, and top, mobile and wear modules in the case of watch faces.
227227
*/
228-
protected File createProject(boolean external)
228+
protected File createProject(boolean external, String password)
229229
throws IOException, SketchException {
230230
tmpFolder = createTempBuildFolder(sketch);
231231
System.out.println(AndroidMode.getTextString("android_build.error.build_folder", tmpFolder.getAbsolutePath()));
@@ -249,7 +249,7 @@ protected File createProject(boolean external)
249249
if (sketchClassName != null) {
250250
renderer = info.getRenderer();
251251
writeMainClass(srcFolder, renderer, external);
252-
createTopModule("':" + module +"'");
252+
createTopModule("':" + module +"'", password);
253253
createAppModule(module);
254254
}
255255

@@ -338,7 +338,7 @@ protected boolean gradleBuild() throws SketchException {
338338
// Gradle modules
339339

340340

341-
private void createTopModule(String projectModules)
341+
private void createTopModule(String projectModules, String keyPassword)
342342
throws IOException {
343343
HashMap<String, String> replaceMap = new HashMap<String, String>();
344344

@@ -349,7 +349,13 @@ private void createTopModule(String projectModules)
349349

350350
File gradlePropsTemplate = mode.getContentFile("templates/" + GRADLE_PROPERTIES_TEMPLATE);
351351
File gradlePropsFile = new File(tmpFolder, "gradle.properties");
352-
Util.copyFile(gradlePropsTemplate, gradlePropsFile);
352+
replaceMap.clear();
353+
replaceMap.put("@@keystore_file@@", AndroidKeyStore.getKeyStore().getAbsolutePath());
354+
replaceMap.put("@@key_alias@@", AndroidKeyStore.ALIAS_STRING);
355+
replaceMap.put("@@key_password@@", keyPassword);
356+
357+
AndroidUtil.createFileFromTemplate(gradlePropsTemplate, gradlePropsFile, replaceMap);
358+
// Util.copyFile(gradlePropsTemplate, gradlePropsFile);
353359

354360
File settingsTemplate = mode.getContentFile("templates/" + GRADLE_SETTINGS_TEMPLATE);
355361
File settingsFile = new File(tmpFolder, "settings.gradle");
@@ -720,7 +726,7 @@ public File exportProject() throws IOException, SketchException {
720726
target = "debug";
721727

722728
exportProject = true;
723-
File projectFolder = createProject(false);
729+
File projectFolder = createProject(false, "");
724730
exportProject = false;
725731

726732
File exportFolder = createExportFolder("android");
@@ -735,11 +741,11 @@ public File exportProject() throws IOException, SketchException {
735741

736742

737743
public File exportBundle(String keyStorePassword) throws Exception {
738-
File projectFolder = buildBundle("release");
744+
File projectFolder = buildBundle("release", keyStorePassword);
739745
if (projectFolder == null) return null;
740746

741-
File signedPackage = signPackage(projectFolder, keyStorePassword, "aab");
742-
if (signedPackage == null) return null;
747+
// File signedPackage = signPackage(projectFolder, keyStorePassword, "aab");
748+
// if (signedPackage == null) return null;
743749

744750
// Final export folder
745751
File exportFolder = createExportFolder("buildBundle");
@@ -753,11 +759,11 @@ public File exportBundle(String keyStorePassword) throws Exception {
753759

754760

755761
public File exportPackage(String keyStorePassword) throws Exception {
756-
File projectFolder = build("release");
762+
File projectFolder = build("release", keyStorePassword);
757763
if (projectFolder == null) return null;
758764

759-
File signedPackage = signPackage(projectFolder, keyStorePassword, "apk");
760-
if (signedPackage == null) return null;
765+
// File signedPackage = signPackage(projectFolder, keyStorePassword, "apk");
766+
// if (signedPackage == null) return null;
761767

762768
// Final export folder
763769
File exportFolder = createExportFolder("buildPackage");
@@ -766,6 +772,7 @@ public File exportPackage(String keyStorePassword) throws Exception {
766772
}
767773

768774

775+
/*
769776
private File signPackage(File projectFolder, String keyStorePassword, String fileExt) throws Exception {
770777
File keyStore = AndroidKeyStore.getKeyStore();
771778
if (keyStore == null) return null;
@@ -836,7 +843,8 @@ private File zipalignPackage(File signedPackage, File projectFolder, String file
836843
837844
if (alignedPackage.exists()) return alignedPackage;
838845
return null;
839-
}
846+
}
847+
*/
840848

841849

842850
//---------------------------------------------------------------------------
@@ -941,7 +949,7 @@ private void renameAAB() {
941949
String aabName = getPathToAAB() + module + "-" + suffix + ".aab";
942950
final File aabFile = new File(tmpFolder, aabName);
943951
if (aabFile.exists()) {
944-
String suffixNew = target.equals("release") ? "release_unsigned" : "debug";
952+
String suffixNew = target.equals("release") ? "release" : "debug";
945953
String aabNameNew = getPathToAAB() +
946954
sketch.getName().toLowerCase() + "_" + suffixNew + ".aab";
947955
final File aabFileNew = new File(tmpFolder, aabNameNew);
@@ -955,11 +963,11 @@ private String getPathToAAB() {
955963

956964

957965
private void renameAPK() {
958-
String suffix = target.equals("release") ? "release-unsigned" : "debug";
966+
String suffix = target.equals("release") ? "release" : "debug";
959967
String apkName = getPathToAPK() + module + "-" + suffix + ".apk";
960968
final File apkFile = new File(tmpFolder, apkName);
961969
if (apkFile.exists()) {
962-
String suffixNew = target.equals("release") ? "release_unsigned" : "debug";
970+
String suffixNew = target.equals("release") ? "release" : "debug";
963971
String apkNameNew = getPathToAPK() +
964972
sketch.getName().toLowerCase() + "_" + suffixNew + ".apk";
965973
final File apkFileNew = new File(tmpFolder, apkNameNew);

mode/src/processing/mode/android/AndroidKeyStore.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
* their apps.
3333
*/
3434
public class AndroidKeyStore {
35-
public static final String ALIAS_STRING = "processing-keystore";
36-
public static final String KEYSTORE_FILE_NAME = "android-release-key.keystore";
35+
public static final String ALIAS_STRING = "p5android-key";
36+
public static final int KEY_VALIDITY_YEARS = 25;
37+
public static final String KEYSTORE_FILE_NAME = "processing-upload-keystore.jks";
3738

3839
public static File getKeyStore() {
3940
return getKeyStore(KEYSTORE_FILE_NAME);
@@ -78,7 +79,7 @@ public static void generateKeyStore(String password,
7879
"-alias", ALIAS_STRING,
7980
"-keyalg", "RSA",
8081
"-keysize", "2048",
81-
"-validity", "10000",
82+
"-validity", Integer.toString(KEY_VALIDITY_YEARS * 365),
8283
"-keypass", password,
8384
"-storepass", password,
8485
"-dname", dname

mode/src/processing/mode/android/AndroidMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void handleRunEmulator(Sketch sketch, AndroidEditor editor,
238238
AndroidBuild build = new AndroidBuild(sketch, this, editor.getAppComponent());
239239

240240
listener.statusNotice(AndroidMode.getTextString("android_mode.status.building_project"));
241-
build.build("debug");
241+
build.build("debug", "");
242242

243243
boolean avd = AVD.ensureProperAVD(editor, this, sdk, build.isWear());
244244
if (!avd) {
@@ -273,7 +273,7 @@ public void handleRunDevice(Sketch sketch, AndroidEditor editor,
273273
AndroidBuild build = new AndroidBuild(sketch, this, editor.getAppComponent());
274274

275275
listener.statusNotice(AndroidMode.getTextString("android_mode.status.building_project"));
276-
File projectFolder = build.build("debug");
276+
File projectFolder = build.build("debug", "");
277277
if (projectFolder == null) {
278278
listener.statusError(AndroidMode.getTextString("android_mode.status.project_build_failed"));
279279
return;

mode/src/processing/mode/android/Commander.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private void execute() {
237237
sketch = new Sketch(pdePath, androidMode);
238238
if (task == BUILD || task == RUN) {
239239
AndroidBuild build = new AndroidBuild(sketch, androidMode, appComponent);
240-
build.build(target);
240+
build.build(target, "");
241241

242242
if (task == RUN) {
243243
AndroidRunner runner = new AndroidRunner(build, this);

mode/templates/ARBuild.gradle.tmpl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@ android {
1717
sourceCompatibility JavaVersion.VERSION_1_8
1818
targetCompatibility JavaVersion.VERSION_1_8
1919
}
20+
signingConfigs {
21+
release {
22+
if (project.hasProperty('PROCESSING_UPLOAD_KEYSTORE_FILE')) {
23+
storeFile file(PROCESSING_UPLOAD_KEYSTORE_FILE)
24+
storePassword PROCESSING_UPLOAD_STORE_PASSWORD
25+
keyAlias PROCESSING_UPLOAD_KEY_ALIAS
26+
keyPassword PROCESSING_UPLOAD_KEY_PASSWORD
27+
}
28+
}
29+
}
2030
buildTypes {
2131
debug {
22-
debuggable true
32+
debuggable true
2333
}
2434
release {
2535
minifyEnabled false
36+
signingConfig signingConfigs.release
2637
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2738
}
2839
}

mode/templates/ARBuildECJ.gradle.tmpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@ android {
1717
sourceCompatibility JavaVersion.VERSION_1_8
1818
targetCompatibility JavaVersion.VERSION_1_8
1919
}
20+
signingConfigs {
21+
release {
22+
if (project.hasProperty('PROCESSING_UPLOAD_KEYSTORE_FILE')) {
23+
storeFile file(PROCESSING_UPLOAD_KEYSTORE_FILE)
24+
storePassword PROCESSING_UPLOAD_STORE_PASSWORD
25+
keyAlias PROCESSING_UPLOAD_KEY_ALIAS
26+
keyPassword PROCESSING_UPLOAD_KEY_PASSWORD
27+
}
28+
}
29+
}
2030
buildTypes {
2131
debug {
2232
debuggable true
2333
}
2434
release {
2535
minifyEnabled false
36+
signingConfig signingConfigs.release
2637
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2738
}
2839
}

mode/templates/AppBuild.gradle.tmpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,23 @@ android {
1919
sourceCompatibility JavaVersion.VERSION_1_8
2020
targetCompatibility JavaVersion.VERSION_1_8
2121
}
22+
signingConfigs {
23+
release {
24+
if (project.hasProperty('PROCESSING_UPLOAD_KEYSTORE_FILE')) {
25+
storeFile file(PROCESSING_UPLOAD_KEYSTORE_FILE)
26+
storePassword PROCESSING_UPLOAD_STORE_PASSWORD
27+
keyAlias PROCESSING_UPLOAD_KEY_ALIAS
28+
keyPassword PROCESSING_UPLOAD_KEY_PASSWORD
29+
}
30+
}
31+
}
2232
buildTypes {
2333
debug {
2434
debuggable true
2535
}
2636
release {
2737
minifyEnabled false
38+
signingConfig signingConfigs.release
2839
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2940
}
3041
}

mode/templates/AppBuildECJ.gradle.tmpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,23 @@ android {
1919
sourceCompatibility JavaVersion.VERSION_1_8
2020
targetCompatibility JavaVersion.VERSION_1_8
2121
}
22+
signingConfigs {
23+
release {
24+
if (project.hasProperty('PROCESSING_UPLOAD_KEYSTORE_FILE')) {
25+
storeFile file(PROCESSING_UPLOAD_KEYSTORE_FILE)
26+
storePassword PROCESSING_UPLOAD_STORE_PASSWORD
27+
keyAlias PROCESSING_UPLOAD_KEY_ALIAS
28+
keyPassword PROCESSING_UPLOAD_KEY_PASSWORD
29+
}
30+
}
31+
}
2232
buildTypes {
2333
debug {
2434
debuggable true
2535
}
2636
release {
2737
minifyEnabled false
38+
signingConfig signingConfigs.release
2839
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2940
}
3041
}

mode/templates/Properties.gradle.tmpl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
org.gradle.jvmargs=-Xmx1536m
22
android.enableJetifier=true
3-
android.useAndroidX=true
3+
android.useAndroidX=true
4+
5+
PROCESSING_UPLOAD_KEYSTORE_FILE=@@keystore_file@@
6+
PROCESSING_UPLOAD_KEY_ALIAS=@@key_alias@@
7+
PROCESSING_UPLOAD_STORE_PASSWORD=@@key_password@@
8+
PROCESSING_UPLOAD_KEY_PASSWORD=@@key_password@@
9+
10+
11+
12+

mode/templates/VRBuild.gradle.tmpl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@ android {
1717
sourceCompatibility JavaVersion.VERSION_1_8
1818
targetCompatibility JavaVersion.VERSION_1_8
1919
}
20+
signingConfigs {
21+
release {
22+
if (project.hasProperty('PROCESSING_UPLOAD_KEYSTORE_FILE')) {
23+
storeFile file(PROCESSING_UPLOAD_KEYSTORE_FILE)
24+
storePassword PROCESSING_UPLOAD_STORE_PASSWORD
25+
keyAlias PROCESSING_UPLOAD_KEY_ALIAS
26+
keyPassword PROCESSING_UPLOAD_KEY_PASSWORD
27+
}
28+
}
29+
}
2030
buildTypes {
2131
debug {
2232
debuggable true
23-
}
33+
}
2434
release {
2535
minifyEnabled false
36+
signingConfig signingConfigs.release
2637
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2738
}
2839
}

mode/templates/VRBuildECJ.gradle.tmpl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@ android {
1717
sourceCompatibility JavaVersion.VERSION_1_8
1818
targetCompatibility JavaVersion.VERSION_1_8
1919
}
20+
signingConfigs {
21+
release {
22+
if (project.hasProperty('PROCESSING_UPLOAD_KEYSTORE_FILE')) {
23+
storeFile file(PROCESSING_UPLOAD_KEYSTORE_FILE)
24+
storePassword PROCESSING_UPLOAD_STORE_PASSWORD
25+
keyAlias PROCESSING_UPLOAD_KEY_ALIAS
26+
keyPassword PROCESSING_UPLOAD_KEY_PASSWORD
27+
}
28+
}
29+
}
2030
buildTypes {
2131
debug {
2232
debuggable true
23-
}
33+
}
2434
release {
2535
minifyEnabled false
36+
signingConfig signingConfigs.release
2637
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2738
}
2839
}

mode/templates/WearBuild.gradle.tmpl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,23 @@ android {
1313
sourceCompatibility JavaVersion.VERSION_1_8
1414
targetCompatibility JavaVersion.VERSION_1_8
1515
}
16+
signingConfigs {
17+
release {
18+
if (project.hasProperty('PROCESSING_UPLOAD_KEYSTORE_FILE')) {
19+
storeFile file(PROCESSING_UPLOAD_KEYSTORE_FILE)
20+
storePassword PROCESSING_UPLOAD_STORE_PASSWORD
21+
keyAlias PROCESSING_UPLOAD_KEY_ALIAS
22+
keyPassword PROCESSING_UPLOAD_KEY_PASSWORD
23+
}
24+
}
25+
}
1626
buildTypes {
1727
debug {
1828
debuggable true
19-
}
29+
}
2030
release {
2131
minifyEnabled false
32+
signingConfig signingConfigs.release
2233
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2334
}
2435
}

0 commit comments

Comments
 (0)