I want to create few library (core and modules), add all this libraries to application and call methods from modules in core library. All modules should be optional. For example, as I see it:
Application build.gradle
:
compile('core-library:1.0@aar')
compile('module1-library:1.0@aar')
compile('module2-library:1.0@aar')
compile('module3-library:1.0@aar')
In every module define class and methods with same name:
public class ModuleClass {
public int moduleMethod1() {
// Do something and return result
return 1;
}
public String moduleMethod2() {
return "Some String";
}
}
In core library:
for(ModuleClass c : getAllModules()) {
Log.d("tag", "Result: " + c.moduleMethod1() + " / " + c.moduleMethod2();
}
Sure that is just pseudo-code. How to implement it or something like?
Updated:
Core module build.gradle
:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildConfigField "String[]", "KNOWN_MODULES", "{" +
"\"module1\"," +
"\"module2\"" +
"}"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compileOnly project(':module1')
compileOnly project(':module2')
testCompile 'junit:junit:4.12'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}