11apply plugin : ' com.android.application'
22apply plugin : ' com.google.devtools.ksp'
3- apply plugin : ' kotlin-android'
43apply plugin : ' kotlin-parcelize'
54
65def commitSHA1 = ' COMMIT_SHA1'
@@ -93,11 +92,11 @@ dependencies {
9392}
9493
9594android {
96- compileSdkVersion sdkCompileVersion
95+ compileSdk sdkCompileVersion
9796
9897 defaultConfig {
99- minSdkVersion sdkMinVersion
100- targetSdkVersion sdkTargetVersion
98+ minSdk sdkMinVersion
99+ targetSdk sdkTargetVersion
101100
102101 testInstrumentationRunner " com.owncloud.android.utils.OCTestAndroidJUnitRunner"
103102
@@ -113,10 +112,6 @@ android {
113112 targetCompatibility JavaVersion . VERSION_17
114113 }
115114
116- kotlinOptions {
117- jvmTarget = JavaVersion . VERSION_17 . toString()
118- }
119-
120115 sourceSets {
121116 androidTest. java. srcDirs + = " src/test-common/java"
122117 test. java. srcDirs + = " src/test-common/java"
@@ -166,11 +161,6 @@ android {
166161 }
167162 }
168163
169- applicationVariants. all { variant ->
170- def appName = System . env. OC_APP_NAME
171- setOutputFileName(variant, appName, project)
172- }
173-
174164 testOptions {
175165 packagingOptions {
176166 jniLibs {
@@ -183,9 +173,10 @@ android {
183173
184174 buildFeatures {
185175 viewBinding true
176+ buildConfig true
186177 }
187178
188- packagingOptions {
179+ packaging {
189180 resources. excludes. add(" META-INF/*" )
190181 }
191182
@@ -194,50 +185,23 @@ android {
194185}
195186
196187// Updates output file names of a given variant to format
197- // [appName].[variant.versionName].[OC_BUILD_NUMBER]-[variant.name].apk.
198- //
199- // OC_BUILD_NUMBER is an environment variable read directly in this method. If undefined, it's not added.
200- //
201- // @param variant Build variant instance which output file name will be updated.
202- // @param appName String to use as first part of the new file name. May be undefined, the original
203- // project.archivesBaseName property will be used instead.
204- // @param callerProject Caller project.
205-
206- def setOutputFileName (variant , appName , callerProject ) {
207- logger. info(" Setting new name for output of variant $variant . name " )
208-
209- def originalFile = variant. outputs[0 ]. outputFile
210- def originalName = originalFile. name
211- println " originalName is $originalName "
212-
213- def newName = " "
214-
215- if (appName) {
216- newName + = appName
217- } else {
218- newName + = " owncloud"
219- }
220-
221- def versionName = " $variant . mergedFlavor . versionName "
222- if (variant. mergedFlavor. manifestPlaceholders. versionName != null ) {
223- versionName = " $variant . mergedFlavor . manifestPlaceholders . versionName "
224- }
225- if (variant. buildType. manifestPlaceholders. versionName != null ) {
226- versionName = " $variant . buildType . manifestPlaceholders . versionName "
227- }
228- newName + = " _$versionName "
229-
230- def buildNumber = System . env. OC_BUILD_NUMBER
231- if (buildNumber) {
232- newName + = " _$buildNumber "
233- }
234-
235- newName + = originalName. substring(callerProject. archivesBaseName. length())
236-
237- println " $variant . name : newName is $newName "
238-
239- variant. outputs. all {
240- outputFileName = newName
188+ // [appName].[variant.versionName].[OC_BUILD_NUMBER]-[variant.name].apk using the new AGP Variant API (androidComponents)
189+ androidComponents {
190+ onVariants(selector(). all()) { variant ->
191+ def appName = System . env. OC_APP_NAME ?: " owncloud"
192+ def buildNumber = System . env. OC_BUILD_NUMBER
193+ variant. outputs. each { output ->
194+ if (output. outputType == com.android.build.api.variant.VariantOutputConfiguration.OutputType . SINGLE ) {
195+ output. outputFileName. set(output. versionName. map { versionName ->
196+ def newName = appName + " _" + versionName
197+ if (buildNumber) {
198+ newName + = " _" + buildNumber
199+ }
200+ newName + = " -" + variant. name + " .apk"
201+ newName
202+ })
203+ }
204+ }
241205 }
242206}
243207
0 commit comments