From 3a7ed157bd0d68261aa4406babe1a1ae9acbc9e3 Mon Sep 17 00:00:00 2001 From: Ryan Fischbach Date: Fri, 29 Jul 2016 15:56:11 -0400 Subject: [PATCH] App -> AppAsLib -> MyLib -> SubLib1 / 2. Flavors can get complex with libraries. --- .idea/compiler.xml | 1 + .idea/encodings.xml | 6 + .idea/gradle.xml | 14 +- .idea/misc.xml | 25 +++- .idea/modules.xml | 5 +- app/app.iml | 120 ++++++++++----- app/build.gradle | 44 +++++- app/src/main/res/layout/activity_main.xml | 25 ++-- applib/.gitignore | 1 + applib/applib.iml | 141 ++++++++++++++++++ applib/build.gradle | 50 +++++++ applib/proguard-rules.pro | 17 +++ .../com/example/applib/ApplicationTest.java | 13 ++ applib/src/main/AndroidManifest.xml | 11 ++ applib/src/main/res/values/strings.xml | 4 + .../com/example/applib/ExampleUnitTest.java | 15 ++ mylib/build.gradle | 15 +- mylib/mylib.iml | 58 ++++--- mylib/src/dev/res/values/strings.xml | 4 + mylib/src/main/res/values/strings.xml | 2 + settings.gradle | 2 +- sublib1/.gitignore | 1 + sublib1/build.gradle | 25 ++++ sublib1/proguard-rules.pro | 17 +++ .../com/example/library1/ApplicationTest.java | 13 ++ sublib1/src/main/AndroidManifest.xml | 11 ++ .../com/example/library1/MySubLib1Class.java | 9 ++ sublib1/src/main/res/values/strings.xml | 4 + .../com/example/library1/ExampleUnitTest.java | 15 ++ sublib1/sublib1.iml | 105 +++++++++++++ sublib2/.gitignore | 1 + sublib2/build.gradle | 25 ++++ sublib2/proguard-rules.pro | 17 +++ .../com/example/library2/ApplicationTest.java | 13 ++ sublib2/src/main/AndroidManifest.xml | 11 ++ sublib2/src/main/res/values/strings.xml | 4 + .../com/example/library2/ExampleUnitTest.java | 15 ++ sublib2/sublib2.iml | 105 +++++++++++++ 38 files changed, 886 insertions(+), 78 deletions(-) create mode 100644 .idea/encodings.xml mode change 100644 => 100755 app/app.iml mode change 100644 => 100755 app/build.gradle mode change 100644 => 100755 app/src/main/res/layout/activity_main.xml create mode 100644 applib/.gitignore create mode 100644 applib/applib.iml create mode 100644 applib/build.gradle create mode 100644 applib/proguard-rules.pro create mode 100644 applib/src/androidTest/java/com/example/applib/ApplicationTest.java create mode 100644 applib/src/main/AndroidManifest.xml create mode 100644 applib/src/main/res/values/strings.xml create mode 100644 applib/src/test/java/com/example/applib/ExampleUnitTest.java mode change 100644 => 100755 mylib/build.gradle mode change 100644 => 100755 mylib/mylib.iml create mode 100755 mylib/src/dev/res/values/strings.xml mode change 100644 => 100755 mylib/src/main/res/values/strings.xml mode change 100644 => 100755 settings.gradle create mode 100644 sublib1/.gitignore create mode 100644 sublib1/build.gradle create mode 100644 sublib1/proguard-rules.pro create mode 100644 sublib1/src/androidTest/java/com/example/library1/ApplicationTest.java create mode 100644 sublib1/src/main/AndroidManifest.xml create mode 100644 sublib1/src/main/java/com/example/library1/MySubLib1Class.java create mode 100644 sublib1/src/main/res/values/strings.xml create mode 100644 sublib1/src/test/java/com/example/library1/ExampleUnitTest.java create mode 100644 sublib1/sublib1.iml create mode 100644 sublib2/.gitignore create mode 100644 sublib2/build.gradle create mode 100644 sublib2/proguard-rules.pro create mode 100644 sublib2/src/androidTest/java/com/example/library2/ApplicationTest.java create mode 100644 sublib2/src/main/AndroidManifest.xml create mode 100644 sublib2/src/main/res/values/strings.xml create mode 100644 sublib2/src/test/java/com/example/library2/ExampleUnitTest.java create mode 100644 sublib2/sublib2.iml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 1f2af51..9a8b7e5 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,7 @@ + @@ -66,7 +64,18 @@ - 1.8 + 1.7 + + + + + + + \ No newline at end of file + diff --git a/app/app.iml b/app/app.iml old mode 100644 new mode 100755 index 51b2034..2a1e29f --- a/app/app.iml +++ b/app/app.iml @@ -8,15 +8,12 @@ - - - + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -50,6 +82,13 @@ + + + + + + + @@ -57,6 +96,13 @@ + + + + + + + @@ -64,34 +110,38 @@ + + + + - - + - - - + + + + - - - - - + - + + - - - + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle old mode 100644 new mode 100755 index 00fb6fa..a67e0c6 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,6 +17,24 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + productFlavors { + dev { + // Your dev tweaks here + minSdkVersion 21 + } + prod { + // Your prod tweaks here + minSdkVersion 16 + } + applibdev { + // Your dev tweaks here + minSdkVersion 21 + } + applibprod { + // Your prod tweaks here + minSdkVersion 16 + } + } } configurations { @@ -24,15 +42,33 @@ configurations { prodDebugCompile devReleaseCompile prodReleaseCompile + + applibdevDebugCompile + applibdevReleaseCompile + applibprodDebugCompile + applibprodReleaseCompile } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1' - devDebugCompile project(path: ':mylib', configuration: 'devDebug') - prodDebugCompile project(path: ':mylib', configuration: 'prodDebug') + Map customDeps = new HashMap() + + customDeps.put("devDebugCompile", dependencies.project(path: ":mylib", configuration: "devDebug")) + customDeps.put("prodDebugCompile", dependencies.project(path: ":mylib", configuration: "prodDebug")) + customDeps.put("devReleaseCompile", dependencies.project(path: ":mylib", configuration: "devRelease")) + customDeps.put("prodReleaseCompile", dependencies.project(path: ":mylib", configuration: "prodRelease")) - devReleaseCompile project(path: ':mylib', configuration: 'devRelease') - prodReleaseCompile project(path: ':mylib', configuration: 'prodRelease') + customDeps.put("applibdevDebugCompile", dependencies.project(path: ":applib", configuration: "devDebug")) + customDeps.put("applibdevReleaseCompile", dependencies.project(path: ":applib", configuration: "devRelease")) + customDeps.put("applibprodDebugCompile", dependencies.project(path: ":applib", configuration: "prodDebug")) + customDeps.put("applibprodReleaseCompile", dependencies.project(path: ":applib", configuration: "prodRelease")) + + configurations.all({ config -> + Dependency d = customDeps.get(config.name) + if (d != null) { + config.dependencies.add(d) + } + }) } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml old mode 100644 new mode 100755 index f7158b8..0cc579d --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,11 +1,18 @@ - - - + + + + + + - + diff --git a/applib/.gitignore b/applib/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/applib/.gitignore @@ -0,0 +1 @@ +/build diff --git a/applib/applib.iml b/applib/applib.iml new file mode 100644 index 0000000..936d751 --- /dev/null +++ b/applib/applib.iml @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/applib/build.gradle b/applib/build.gradle new file mode 100644 index 0000000..e68c942 --- /dev/null +++ b/applib/build.gradle @@ -0,0 +1,50 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 24 + buildToolsVersion "24.0.1" + publishNonDefault true + + defaultConfig { + minSdkVersion 9 + targetSdkVersion 24 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + productFlavors { + dev { + // Your dev tweaks here + minSdkVersion 21 + } + prod { + // Your prod tweaks here + minSdkVersion 16 + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:24.1.1' + + Map customDeps = new HashMap() + + customDeps.put("devDebugCompile", dependencies.project(path: ":mylib", configuration: "devDebug")) + customDeps.put("prodDebugCompile", dependencies.project(path: ":mylib", configuration: "prodDebug")) + customDeps.put("devReleaseCompile", dependencies.project(path: ":mylib", configuration: "devRelease")) + customDeps.put("prodReleaseCompile", dependencies.project(path: ":mylib", configuration: "prodRelease")) + + configurations.all({ config -> + Dependency d = customDeps.get(config.name) + if (d != null) { + config.dependencies.add(d) + } + }) +} diff --git a/applib/proguard-rules.pro b/applib/proguard-rules.pro new file mode 100644 index 0000000..537c3f4 --- /dev/null +++ b/applib/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /DevApps/android-adt/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/applib/src/androidTest/java/com/example/applib/ApplicationTest.java b/applib/src/androidTest/java/com/example/applib/ApplicationTest.java new file mode 100644 index 0000000..486967f --- /dev/null +++ b/applib/src/androidTest/java/com/example/applib/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.istresearch.applib; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} diff --git a/applib/src/main/AndroidManifest.xml b/applib/src/main/AndroidManifest.xml new file mode 100644 index 0000000..c453b57 --- /dev/null +++ b/applib/src/main/AndroidManifest.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/applib/src/main/res/values/strings.xml b/applib/src/main/res/values/strings.xml new file mode 100644 index 0000000..5bc6c7c --- /dev/null +++ b/applib/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + AppAsLib + App As Lib + diff --git a/applib/src/test/java/com/example/applib/ExampleUnitTest.java b/applib/src/test/java/com/example/applib/ExampleUnitTest.java new file mode 100644 index 0000000..9376f60 --- /dev/null +++ b/applib/src/test/java/com/example/applib/ExampleUnitTest.java @@ -0,0 +1,15 @@ +package com.istresearch.applib; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * To work on unit tests, switch the Test Artifact in the Build Variants view. + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} diff --git a/mylib/build.gradle b/mylib/build.gradle old mode 100644 new mode 100755 index d370075..6f5bea0 --- a/mylib/build.gradle +++ b/mylib/build.gradle @@ -3,6 +3,7 @@ apply plugin: 'com.android.library' android { compileSdkVersion 23 buildToolsVersion "23.0.1" + publishNonDefault true defaultConfig { minSdkVersion 16 @@ -19,7 +20,7 @@ android { productFlavors { dev { // Your dev tweaks here - minSdkVersion 23 + minSdkVersion 21 } prod { // Your prod tweaks here @@ -31,4 +32,16 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1' + + Map customDeps = new HashMap() + customDeps.put("devDebugCompile", dependencies.project(path: ':sublib1')) + customDeps.put("prodDebugCompile", dependencies.project(path: ':sublib2')) + + configurations.all({ config -> + Dependency d = customDeps.get(config.name) + if (d != null) { + config.dependencies.add(d) + } + }) + } diff --git a/mylib/mylib.iml b/mylib/mylib.iml old mode 100644 new mode 100755 index 9a851b3..e6022e0 --- a/mylib/mylib.iml +++ b/mylib/mylib.iml @@ -12,16 +12,13 @@