Skip to content

支持动态配置编译哪些模块,以及模块可以单独编译为可运行 app #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

apply from: "config.gradle"
buildscript {
repositories {
jcenter()
Expand All @@ -14,6 +14,10 @@ buildscript {
}

allprojects {
configurations.all {
// don't cache changing modules at all
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
repositories {
jcenter()
}
Expand Down
100 changes: 100 additions & 0 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*全局配置信息及第三方依赖统一管理*/
ext {

appModuleMusicDemo = project.hasProperty("appModuleMusicDemo") ? project.property("appModuleMusicDemo").equals("1").toString() : false
appModulePicDemo = project.hasProperty("appModulePicDemo") ? project.property("appModulePicDemo").equals("1").toString() : false
appModuleWebDemo = project.hasProperty("appModuleWebDemo") ? project.property("appModuleWebDemo").equals("1").toString() : false


android = [compileSdkVersion : 27,
buildToolsVersion : '27.0.3',
minSdkVersion : 17,
targetSdkVersion : 23,
versionCode : 1,
versionName : "1.0.0",
applicationId : "com.example.tome.framedemomo2",

androidSupportSdkVersion: "27.0.2"

]

dependencies = ["appcompat_v7" : "com.android.support:appcompat-v7:${android["androidSupportSdkVersion"]}",
"constraint_layout" : 'com.android.support.constraint:constraint-layout:1.1.1',
"runner" : 'com.android.support.test:runner:1.0.1',
"espresso_core" : 'com.android.support.test.espresso:espresso-core:3.0.1',
"junit" : 'junit:junit:4.12',
"support_annotations" : 'com.android.support:support-annotations:24.0.0',
"design" : "com.android.support:design:${android["androidSupportSdkVersion"]}",
"support-v4" : "com.android.support:support-v4:${android["androidSupportSdkVersion"]}",
"cardview-v7" : "com.android.support:cardview-v7:${android["androidSupportSdkVersion"]}",
"recyclerview-v7" : "com.android.support:recyclerview-v7:${android["androidSupportSdkVersion"]}",

//方法数超过65535解决方法64K MultiDex分包方法
"multidex" : 'com.android.support:multidex:1.0.2',

//路由
"arouter_api" : 'com.alibaba:arouter-api:1.2.4',
"arouter_compiler" : 'com.alibaba:arouter-compiler:1.1.4',
"arouter_annotation" : 'com.alibaba:arouter-annotation:1.0.4',

//黄油刀
"butterknife_compiler" : 'com.jakewharton:butterknife-compiler:8.4.0',
"butterknife" : 'com.jakewharton:butterknife:8.4.0',

//网络
//retrofit2包含okhttp
//"okhttp3" : 'com.squareup.okhttp3:okhttp:3.9.0',
"retrofit2" : 'com.squareup.retrofit2:retrofit:2.3.0',
"converter-gson" : 'com.squareup.retrofit2:converter-gson:2.3.0',
"adapter-rxjava2" : 'com.squareup.retrofit2:adapter-rxjava2:2.3.0',
"rxjava2:rxandroid" : 'io.reactivex.rxjava2:rxandroid:2.0.1',
"rxjava2" : 'io.reactivex.rxjava2:rxjava:2.1.5',
//日志拦截器
"logging-interceptor" : 'com.squareup.okhttp3:logging-interceptor:3.4.1',
//暂时没用上
"rxbinding2" : 'com.jakewharton.rxbinding2:rxbinding:2.1.0',
//日志
"logger" : 'com.orhanobut:logger:2.1.1',
//图片
"glide" : 'com.github.bumptech.glide:glide:4.5.0',
"glide:okhttp3" : 'com.github.bumptech.glide:okhttp3-integration:4.5.0',
//图片选择器
"PictureSelector" : 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.3',
//图片缩放
"photoview" : 'com.github.chrisbanes.photoview:library:1.2.4',
//时间,地址,条件选择器
"pickerView" : 'com.contrarywind:Android-PickerView:3.2.7',
//SmartRefreshLayout
"smartRefreshLayout" : 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.5.1',
"SmartRefreshHeader" : 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.5.1',
//banner
"banner" : 'com.youth.banner:banner:1.4.10',
//eventbus
"eventbus" : 'org.greenrobot:eventbus:3.0.0',
//baseRecyclerViewAdapterHelper
"baseRecyclerViewAdapterHelper" : 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.22',
//Bugly集成
"bugly" : 'com.tencent.bugly:crashreport_upgrade:latest.release',
//仿ios进度条
// "kprogresshud" : 'com.kaopiz:kprogresshud:1.1.0',
//6.0权限管理
"permissionsdispatcher" : 'com.github.hotchemi:permissionsdispatcher:3.0.1',
"permissionsdispatcher_processor": 'com.github.hotchemi:permissionsdispatcher-processor:3.0.1',
//dagger 暂时没用
"dagger" : 'com.google.dagger:dagger:2.0.2',
"dagger-compiler" : 'com.google.dagger:dagger-compiler:2.0.2',
"javax-annotation" : 'org.glassfish:javax.annotation:10.0-b28',
//greendao
"greendao" : 'org.greenrobot:greendao:3.2.2',
//Android屏幕适配
"autolayout" : 'com.zhy:autolayout:1.4.5',
//安卓调试神器-Stetho
"stetho" : 'com.facebook.stetho:stetho:1.5.0',
"stetho-okhttp3" : 'com.facebook.stetho:stetho-okhttp3:1.5.0',
// 仿ios弹出对话窗体
"alertview" : 'com.bigkoo:alertview:1.0.3',
//bugly sdk
"tencent-bugly" : 'com.tencent.bugly:crashreport_upgrade:latest.release',
//节操播放器
"jiecao" : 'fm.jiecao:jiecaovideoplayer:5.7',]
}
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
// 某个模块是否 app 0否 1是
appModulePicDemo = 1
appModuleMusicDemo = 1
appModuleWebDemo = 1
8 changes: 5 additions & 3 deletions macore/src/main/java/com/spinytech/macore/MaApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ public abstract class MaApplication extends Application {
@CallSuper
@Override
public void onCreate() {
// wait for debugger for muti process
// android.os.Debug.waitForDebugger();
super.onCreate();
sInstance = this;
Logger.d(TAG,"Application onCreate start: "+System.currentTimeMillis());
init();
startWideRouter();
initializeLogic();
registerAllApplicationLogic();
dispatchLogic();
instantiateLogic();

Expand Down Expand Up @@ -65,9 +67,9 @@ protected void startWideRouter() {
}
}

public abstract void initializeAllProcessRouter();
public abstract void registerAllProcessRouter();

protected abstract void initializeLogic();
protected abstract void registerAllApplicationLogic();

public abstract boolean needMultipleProcess();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public void onCreate() {

protected void initRouter() {
WideRouter.getInstance(mApplication);
mApplication.initializeAllProcessRouter();
mApplication.registerAllProcessRouter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public IBinder onBind(Intent intent) {
boolean hasRegistered = WideRouter.getInstance(MaApplication.getMaApplication()).checkLocalRouterHasRegistered(domain);
if (!hasRegistered) {
Logger.e(TAG, "Bind error: The local router of process " + domain + " is not bidirectional." +
"\nPlease create a Service extend LocalRouterConnectService then register it in AndroidManifest.xml and the initializeAllProcessRouter method of MaApplication." +
"\nPlease create a Service extend LocalRouterConnectService then register it in AndroidManifest.xml and the registerAllProcessRouter method of MaApplication." +
"\nFor example:" +
"\n<service android:name=\"XXXConnectService\" android:process=\"your process name\"/>" +
"\nWideRouter.registerLocalRouter(\"your process name\",XXXConnectService.class);");
Expand Down
24 changes: 19 additions & 5 deletions maindemo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

apply plugin: 'com.android.application'
def channel = hasProperty("channel") ? property("channel") : "test"

android {
compileSdkVersion 24
Expand All @@ -10,18 +12,22 @@ android {
targetSdkVersion 24
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

// read gradle.properties
buildConfigField "boolean", "channel", project.hasProperty("channel") ? project.property("channel").equals("2").toString() : "false"

}
buildTypes {
release {
manifestPlaceholders = [
"channel": "\"$channel\""
]
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
Expand All @@ -30,8 +36,16 @@ dependencies {
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile project(':macore')
compile project(':musicdemo')
compile project(':picdemo')
compile project(':webdemo')


if (!Boolean.valueOf(rootProject.ext.appModulePicDemo)) {
compile project(':picdemo')
}
if (!Boolean.valueOf(rootProject.ext.appModuleMusicDemo)) {
compile project(':musicdemo')
}
if (!Boolean.valueOf(rootProject.ext.appModuleWebDemo)) {
compile project(':webdemo')
}

}
56 changes: 42 additions & 14 deletions maindemo/src/main/java/com/spinytech/maindemo/MyApplication.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,59 @@
package com.spinytech.maindemo;

import android.util.Pair;

import com.spinytech.macore.MaApplication;
import com.spinytech.macore.multiprocess.BaseApplicationLogic;
import com.spinytech.macore.router.LocalRouterConnectService;
import com.spinytech.macore.router.WideRouter;
import com.spinytech.musicdemo.MusicApplicationLogic;
import com.spinytech.musicdemo.MusicRouterConnectService;
import com.spinytech.picdemo.PicApplicationLogic;
import com.spinytech.picdemo.PicRouterConnectService;
import com.spinytech.webdemo.WebApplicationLogic;

import java.util.LinkedList;

/**
* Created by wanglei on 2016/11/29.
*/

public class MyApplication extends MaApplication {
public static LinkedList<Pair<String,String>> applicationLogic;
public static LinkedList<Pair<String,String>> allProcessRouter;

static {
applicationLogic = new LinkedList<>();
applicationLogic.add(new Pair<String, String>("com.spinytech.maindemo", "com.spinytech.maindemo.MainApplicationLogic"));
applicationLogic.add(new Pair<String, String>("com.spinytech.maindemo", "com.spinytech.webdemo.WebApplicationLogic"));
applicationLogic.add(new Pair<String, String>("com.spinytech.maindemo:music", "com.spinytech.musicdemo.MusicApplicationLogic"));
applicationLogic.add(new Pair<String, String>("com.spinytech.maindemo:pic", "com.spinytech.picdemo.PicApplicationLogic"));


allProcessRouter = new LinkedList<>();
allProcessRouter.add(new Pair<String, String>("com.spinytech.maindemo", "com.spinytech.maindemo.MainRouterConnectService"));
allProcessRouter.add(new Pair<String, String>("com.spinytech.maindemo:music", "com.spinytech.musicdemo.MusicRouterConnectService"));
allProcessRouter.add(new Pair<String, String>("com.spinytech.maindemo:pic", "com.spinytech.picdemo.PicRouterConnectService"));

}
@Override
public void initializeAllProcessRouter() {
WideRouter.registerLocalRouter("com.spinytech.maindemo",MainRouterConnectService.class);
WideRouter.registerLocalRouter("com.spinytech.maindemo:music",MusicRouterConnectService.class);
WideRouter.registerLocalRouter("com.spinytech.maindemo:pic",PicRouterConnectService.class);
public void registerAllProcessRouter() {
for (Pair<String, String> processRouter : allProcessRouter) {
try {
Class<? extends LocalRouterConnectService> localRouterClass = (Class<? extends LocalRouterConnectService>) Class.forName(processRouter.second);
WideRouter.registerLocalRouter(processRouter.first,localRouterClass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}

}

@Override
protected void initializeLogic() {
registerApplicationLogic("com.spinytech.maindemo",999, MainApplicationLogic.class);
registerApplicationLogic("com.spinytech.maindemo",998, WebApplicationLogic.class);
registerApplicationLogic("com.spinytech.maindemo:music",999, MusicApplicationLogic.class);
registerApplicationLogic("com.spinytech.maindemo:pic",999, PicApplicationLogic.class);
protected void registerAllApplicationLogic() {
for (Pair<String, String> processLogic : applicationLogic) {
try {
Class<? extends BaseApplicationLogic> applicationLogicClass = (Class<? extends BaseApplicationLogic>) Class.forName(processLogic.second);
registerApplicationLogic(processLogic.first, 998, applicationLogicClass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}

@Override
Expand Down
21 changes: 21 additions & 0 deletions musicdemo/app/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.spinytech.musicdemo">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

<service android:name=".MusicRouterConnectService"
/>
<service android:name=".MusicService"
/>
<activity android:name=".MusicDemoActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
16 changes: 16 additions & 0 deletions musicdemo/app/java/com/spinytech/musicdemo/MusicDemoActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.spinytech.musicdemo;

import android.app.Activity;
import android.os.Bundle;

public class MusicDemoActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.music_layout);
}


}
6 changes: 6 additions & 0 deletions musicdemo/app/res/layout/music_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

</LinearLayout>
Loading