I have an Android project consisting of two modules: An 'SDK' and a 'demonstration Android app'.
Currently the SDK lives in /path/to/work/dir/sdk
and the app in /path/to/work/dir/demo-app
. Developers open '/path/to/work/dir/demo-app' in Android Studio and can see + edit the source code for both modules at the same time.
We have another Android app, but that includes the SDK as a compiled .aar file and it can't see or edit the "live" source, only the decompiled/debug-symbol-ed one, if that makes sense?
TL;DR I would like to make the SDK into a plain-Java library so that it can be used in non-Android apps, and yet still have it fully editable inside Android Studio as part of the demo app 'project'. How do I do this?
Details
Details of the SDK
The SDK's job is to control some hardware devices on the other end of a socket. It is almost entirely plain Java, but has a few incidental uses of the Android library:
android.util.Log
, associatedTAG
constants in classes, and runtime checks to disable log messages (BuildConfig.DEBUG
)Annotations for static analysis:
@Nullable
,@AnyThread
,@NonNull
,@Nullable
,@UiThread
,@WorkerThread
,@IntRange
,@Size
,@SuppressLint
Incidental use of libraries where Java stdlib was lacking:
android.text.TextUtils
android.support.v4.util.Pair
Its test suite are all "test". There's a single, useless "androidTest" which can just be deleted.
The Gradle build environment is still tailored towards Android, as is the directory structure. i.e. the repo dir looks like this:
/path/to/work/dir/sdk ├───.git │ └───...etc... ├───.gradle │ └───...etc... ├───app │ ├───app.iml │ ├───Mobile-SDK-Android.iml │ ├───proguard-rules.pro │ ├───build │ │ ├───generated │ │ │ └───...etc... │ │ ├───intermediates │ │ │ └───...etc... │ │ ├───outputs │ │ │ └───aar │ │ └───tmp │ │ ├─... │ ├───docs │ ├───libs │ └───src │ ├───androidTest │ │ └───java │ │ └───com │ │ └───...etc... │ ├───main │ │ ├───java │ │ │ └───com │ │ │ └───...etc... │ │ └───res │ │ └───values │ │ └───strings.xml │ └───test │ ├───java │ │ └───com │ │ └───...etc... │ └───resources ├───build │ ├───android-profile │ ├───generated │ └───intermediates └───gradle └───wrapper
and
build.gradle
is as follows:apply plugin: 'com.android.library' android { compileSdkVersion 25 buildToolsVersion '25.0.2' defaultConfig { minSdkVersion 16 targetSdkVersion 25 versionCode 1 versionName "0.7" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { debuggable false } } packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/ASL2.0' } productFlavors { } publishNonDefault true } repositories { ... etc ... } dependencies { // For @Nullable/@NonNull compile 'com.android.support:support-annotations:25.3.1' testCompile 'junit:junit:4.12' ... etc ... }
The 'release build' instructions contains the following:
$ ./gradlew check $ ./gradlew assembleRelease # Then copies and packages app/build/outputs/aar/app-release.aar
Details of the app
The 'Android app' module appears to be normal Android app, e.g. it's using Activity classes and the Android libraries and Android Studio deploys it to devices just fine. There's these gradle scritps:
/path/to/work/dir/demo-app/build.gradle (Project: Demo-App)
/path/to/work/dir/demo-app/settings.gradle (Project Settings)
/path/to/work/dir/demo-app/app/build.gradle (Module: app)
settings.gradle
in it's entirety:
include ':app', ':Mobile-SDK-Android'
project(':Mobile-SDK-Android').projectDir = new File('/path/to/work/dir/sdk/app')
build.gradle
Doesn't contain anything relevant, that I can see?
app/build.gradle
containing these relevant bits:
apply plugin: 'com.android.application'
android {
... etc
}
dependencies {
compile project(path: ':Mobile-SDK-Android', configuration: 'debug')
... etc
}
Required changes?
What is an appropriate sequence of steps to convert the SDK into a "normal" and idiomatic Java library?
e.g.:
- Convert all uses of
android.util.Log
to use e.g.SLF4J
- Convert all annotations to ???
- Re-implement or use alternatives for
TextUtils
andPair
? - Perform some magic on the gradle scripts
- So the output is .jar instead of .aar
- and isn't called app-release.aar
- Is it still possible to have things like
minSdkVersion
? - Is it possible to have an 'android flavour' of this jar file, incase we need to put android specific code in the SDK in future?
- So the output is .jar instead of .aar
- Possibly restructure the SDK's dir to remove the "app" dir?
- ????
n. Profit