Allow Android Java shim to be built as an AAR
authorCole Campbell <cole.campbell@twistedlogik.net>
Tue, 09 Jan 2018 19:11:34 -0500
changeset 11854934d77867168
parent 11853 c7946b873fe8
child 11855 7b4cee950f96
Allow Android Java shim to be built as an AAR
android-project/app/build.gradle
     1.1 --- a/android-project/app/build.gradle	Wed Feb 07 15:05:30 2018 -0800
     1.2 +++ b/android-project/app/build.gradle	Tue Jan 09 19:11:34 2018 -0500
     1.3 @@ -1,10 +1,19 @@
     1.4 -apply plugin: 'com.android.application'
     1.5 +def buildAsLibrary = project.hasProperty('BUILD_AS_LIBRARY');
     1.6 +def buildAsApplication = !buildAsLibrary
     1.7 +if (buildAsApplication) {
     1.8 +    apply plugin: 'com.android.application'
     1.9 +}
    1.10 +else {
    1.11 +    apply plugin: 'com.android.library'
    1.12 +}
    1.13  
    1.14  android {
    1.15      compileSdkVersion 16
    1.16      buildToolsVersion "26.0.1"
    1.17      defaultConfig {
    1.18 -        applicationId "org.libsdl.app"
    1.19 +        if (buildAsApplication) {
    1.20 +            applicationId "org.libsdl.app"
    1.21 +        }
    1.22          minSdkVersion 14
    1.23          targetSdkVersion 16
    1.24          versionCode 1
    1.25 @@ -22,17 +31,32 @@
    1.26              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    1.27          }
    1.28      }
    1.29 -    sourceSets.main {
    1.30 -        jniLibs.srcDir 'libs'
    1.31 -    }
    1.32 -    externalNativeBuild {
    1.33 -        ndkBuild {
    1.34 -            path 'jni/Android.mk'
    1.35 +    if (!project.hasProperty('EXCLUDE_NATIVE_LIBS')) {
    1.36 +        sourceSets.main {
    1.37 +            jniLibs.srcDir 'libs'
    1.38          }
    1.39 +        externalNativeBuild {
    1.40 +            ndkBuild {
    1.41 +                path 'jni/Android.mk'
    1.42 +            }
    1.43 +        }
    1.44 +       
    1.45      }
    1.46      lintOptions {
    1.47          abortOnError false
    1.48      }
    1.49 +    
    1.50 +    if (buildAsLibrary) {
    1.51 +        libraryVariants.all { variant ->
    1.52 +            variant.outputs.each { output ->
    1.53 +                def outputFile = output.outputFile
    1.54 +                if (outputFile != null && outputFile.name.endsWith(".aar")) {
    1.55 +                    def fileName = "org.libsdl.app.aar";
    1.56 +                    output.outputFile = new File(outputFile.parent, fileName);
    1.57 +                }
    1.58 +            }
    1.59 +        }
    1.60 +    }
    1.61  }
    1.62  
    1.63  dependencies {
    1.64 @@ -41,4 +65,4 @@
    1.65          exclude group: 'com.android.support', module: 'support-annotations'
    1.66      })
    1.67      testCompile 'junit:junit:4.12'
    1.68 -}
    1.69 +}
    1.70 \ No newline at end of file