Browse Source

Merge pull request #1699 from owncloud/allow_change_APK_names

Allow changing APK names
David A. Velasco 9 years ago
parent
commit
9090d52c7d
2 changed files with 52 additions and 1 deletions
  1. 44 1
      build.gradle
  2. 8 0
      oc_jb_workaround/build.gradle

+ 44 - 1
build.gradle

@@ -123,4 +123,47 @@ android {
         exclude 'META-INF/LICENSE.txt'
     }
 
-}
+    applicationVariants.all { variant ->
+        def appName = System.env.OC_APP_NAME
+        setOutputFileName(variant, appName, project)
+    }
+}
+
+// Updates output file names of a given variant to format
+// [appName].[variant.versionName].[OC_BUILD_NUMBER]-[variant.name].apk.
+//
+// OC_BUILD_NUMBER is an environment variable read directly in this method. If undefined, it's not added.
+//
+// @param variant           Build variant instance which output file name will be updated.
+// @param appName           String to use as first part of the new file name. May be undefined, the original
+//                          project.archivesBaseName property will be used instead.
+// @param callerProject     Caller project.
+
+def setOutputFileName(variant, appName, callerProject) {
+    logger.info("Setting new name for output of variant $variant.name")
+
+    def originalFile = variant.outputs[0].outputFile;
+    def originalName = originalFile.name;
+    logger.info("$variant.name: originalName is $originalName")
+
+    def newName = ""
+
+    if (appName) {
+        newName += appName
+    } else {
+        newName += callerProject.archivesBaseName
+    }
+
+    newName += "_$variant.versionName"
+
+    def buildNumber = System.env.OC_BUILD_NUMBER
+    if (buildNumber) {
+        newName += ".$buildNumber"
+    }
+
+    newName += originalName.substring(callerProject.archivesBaseName.length())
+
+    logger.quiet("$variant.name: newName is $newName")
+    variant.outputs[0].outputFile = new File(originalFile.parent, newName)
+}
+

+ 8 - 0
oc_jb_workaround/build.gradle

@@ -39,4 +39,12 @@ android {
         debug.setRoot('build-types/debug')
         release.setRoot('build-types/release')
     }
+
+    applicationVariants.all { variant ->
+        def appName = System.env.OC_APP_NAME
+        if (appName) {
+            appName += "_jb_workaround"
+        }
+        setOutputFileName(variant, appName, project)
+    }
 }