Skip to content

Commit

Permalink
feat(android): module builds should fail with aar in lib folder
Browse files Browse the repository at this point in the history
- Breaking change as of Titanium 9.0.0
- Gradle build system won't merge AAR library into build AAR. So, while it compiles, the built AAR is missing classes the app needs to function.
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Feb 13, 2020
1 parent 0616395 commit 0c72020
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions android/templates/module/generated/build.gradle
Expand Up @@ -120,20 +120,34 @@ android {
}
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
// Exclude the C++ runtime and Titanium kroll libraries for all architectures when packaging the AAR file.
// Avoids app build failure due to library file name collision. (Apps will use "titanium.aar" bundled *.so files.)
packagingOptions {
exclude '/lib/**/libc++_shared.so'
exclude '/lib/**/libkroll-v8.so'
}
// Sets the JVM target in order to allow usage of Java 8 features in Kotlin native modules.
kotlinOptions {
jvmTarget = '1.8'
}

// Trigger a build failure if an AAR library was found under the "lib" directory.
// While it will compile with the library, Google's build system won't merge the AAR into this module's AAR.
preBuild.doFirst {
def libDirectory = new File("${projectDir}/../../lib")
if (libDirectory.exists()) {
libDirectory.eachFile {
if (it.name.toLowerCase().endsWith('.aar')) {
def errorMessage =
'AAR files are no longer supported under the "lib" directory. ' +
'You must reference AAR libraries via a "build.gradle" file\'s dependencies section instead.'
throw new GradleException(errorMessage)
}
}
}
}

Expand Down Expand Up @@ -169,12 +183,13 @@ dependencies {
compileOnly files(krollAptJarPath)
kapt files(krollAptJarPath)

// Reference this module's local AAR/JAR file dependencies.
implementation fileTree(dir: "${projectDir}/../../lib", include: ['*.aar', '*.jar'])
// Reference this module's local JAR file dependencies.
implementation fileTree(dir: "${projectDir}/../../lib", include: ['*.jar'])

// Reference the main Titanium library.
implementation 'org.appcelerator:titanium:<%- tiSdkVersion %>'

// Reference the core kotlin library.
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}

Expand Down

0 comments on commit 0c72020

Please sign in to comment.