//控制組件模式和集成模式 if (rootProject.ext.isDouBanApplication) { //是Component,能夠獨立運行 apply plugin: 'com.android.application' } else { //是lib,被依賴 apply plugin: 'com.android.library' }
//控制組件模式和集成模式 if (rootProject.ext.isGankApplication) { apply plugin: 'com.android.application' } else { apply plugin: 'com.android.library' } android { compileSdkVersion rootProject.ext.android["compileSdkVersion"] buildToolsVersion rootProject.ext.android["buildToolsVersion"] defaultConfig { minSdkVersion rootProject.ext.android["minSdkVersion"] targetSdkVersion rootProject.ext.android["targetSdkVersion"] versionCode rootProject.ext.android["versionCode"] versionName rootProject.ext.android["versionName"] if (rootProject.ext.isGankApplication){ //組件模式下設置applicationId applicationId "com.ycbjie.gank" } javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } //jdk1.8 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } sourceSets { main { if (rootProject.ext.isGankApplication) { manifest.srcFile 'src/main/module/AndroidManifest.xml' } else { manifest.srcFile 'src/main/AndroidManifest.xml' } jniLibs.srcDirs = ['libs'] } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':library') annotationProcessor rootProject.ext.dependencies["router-compiler"] }
ext { isApplication = false //false:做爲Lib組件存在, true:做爲application存在 isAndroidApplication = false //玩Android模塊開關,false:做爲Lib組件存在, true:做爲application存在 isLoveApplication = false //愛意表達模塊開關,false:做爲Lib組件存在, true:做爲application存在 isVideoApplication = false //視頻模塊開關,false:做爲Lib組件存在, true:做爲application存在 isNoteApplication = false //記事本模塊開關,false:做爲Lib組件存在, true:做爲application存在 isBookApplication = false //book模塊開關,false:做爲Lib組件存在, true:做爲application存在 isDouBanApplication = false //豆瓣模塊開關,false:做爲Lib組件存在, true:做爲application存在 isGankApplication = false //乾貨模塊開關,false:做爲Lib組件存在, true:做爲application存在 isMusicApplication = false //音樂模塊開關,false:做爲Lib組件存在, true:做爲application存在 isNewsApplication = false //新聞模塊開關,false:做爲Lib組件存在, true:做爲application存在 isToDoApplication = false //todo模塊開關,false:做爲Lib組件存在, true:做爲application存在 isZhiHuApplication = false //知乎模塊開關,false:做爲Lib組件存在, true:做爲application存在 isOtherApplication = false //其餘模塊開關,false:做爲Lib組件存在, true:做爲application存在 android = [ compileSdkVersion : 28, buildToolsVersion : "28.0.3", minSdkVersion : 17, targetSdkVersion : 28, versionCode : 22, versionName : "1.8.2" //必須是int或者float,不然影響線上升級 ] version = [ androidSupportSdkVersion: "28.0.0", retrofitSdkVersion : "2.4.0", glideSdkVersion : "4.8.0", canarySdkVersion : "1.5.4", constraintVersion : "1.0.2" ] dependencies = [ //support "appcompat-v7" : "com.android.support:appcompat-v7:${version["androidSupportSdkVersion"]}", "multidex" : "com.android.support:multidex:1.0.1", //network "retrofit" : "com.squareup.retrofit2:retrofit:${version["retrofitSdkVersion"]}", "retrofit-converter-gson" : "com.squareup.retrofit2:converter-gson:${version["retrofitSdkVersion"]}", "retrofit-adapter-rxjava" : "com.squareup.retrofit2:adapter-rxjava2:${version["retrofitSdkVersion"]}", //這裏省略一部分代碼 ] }
apply plugin: 'com.android.library' android { compileSdkVersion rootProject.ext.android["compileSdkVersion"] buildToolsVersion rootProject.ext.android["buildToolsVersion"] defaultConfig { minSdkVersion rootProject.ext.android["minSdkVersion"] targetSdkVersion rootProject.ext.android["targetSdkVersion"] versionCode rootProject.ext.android["versionCode"] versionName rootProject.ext.android["versionName"] } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) api rootProject.ext.dependencies["appcompat-v7"] api rootProject.ext.dependencies["design"] api rootProject.ext.dependencies["palette"] api rootProject.ext.dependencies["glide"] api (rootProject.ext.dependencies["glide-transformations"]){ exclude module: 'glide' } annotationProcessor rootProject.ext.dependencies["glide-compiler"] api files('libs/tbs_sdk_thirdapp_v3.2.0.jar') api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" //省略部分代碼 }
//控制組件模式和集成模式 if (rootProject.ext.isAndroidApplication) { apply plugin: 'com.android.application' } else { apply plugin: 'com.android.library' }
ext { isAndroidApplication = false //false:做爲Lib組件存在, true:做爲application存在
ext { isAndroidApplication = true //false:做爲Lib組件存在, true:做爲application存在
android { defaultConfig { if (rootProject.ext.isAndroidApplication){ //組件模式下設置applicationId applicationId "com.ycbjie.android" } } sourceSets { main { if (rootProject.ext.isAndroidApplication) { manifest.srcFile 'src/main/module/AndroidManifest.xml' } else { manifest.srcFile 'src/main/AndroidManifest.xml' } jniLibs.srcDirs = ['libs'] } } }
api(rootProject.ext.dependencies["logger"]) { exclude module: 'support-v4'//根據組件名排除 exclude group: 'android.support.v4'//根據包名排除 }
//跳轉 intent.setClass(this,CommentActivity.class); intent.putExtra("id",id); intent.putExtra("allNum",allNum); intent.putExtra("shortNum",shortNum); intent.putExtra("longNum",longNum); startActivity(intent); //接收 Intent intent = getIntent(); int allNum = intent.getExtras().getInt("allNum"); int shortNum = intent.getExtras().getInt("shortNum"); int longNum = intent.getExtras().getInt("longNum"); int id = intent.getExtras().getInt("id");
/** * DO NOT EDIT THIS FILE!!! IT WAS GENERATED BY AROUTER. */ public class ARouter$$Group$$video implements IRouteGroup { @Override public void loadInto(Map<String, RouteMeta> atlas) { atlas.put("/video/VideoActivity", RouteMeta.build(RouteType.ACTIVITY, VideoActivity.class, "/video/videoactivity", "video", null, -1, -2147483648)); } }
private Object _navigation(final Context context, final Postcard postcard, final int requestCode, final NavigationCallback callback) { final Context currentContext = null == context ? mContext : context; switch (postcard.getType()) { case ACTIVITY: // Build intent final Intent intent = new Intent(currentContext, postcard.getDestination()); intent.putExtras(postcard.getExtras()); // Set flags. int flags = postcard.getFlags(); if (-1 != flags) { intent.setFlags(flags); } else if (!(currentContext instanceof Activity)) { // Non activity, need less one flag. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } // Set Actions String action = postcard.getAction(); if (!TextUtils.isEmpty(action)) { intent.setAction(action); } // Navigation in main looper. runInMainThread(new Runnable() { @Override public void run() { startActivity(requestCode, currentContext, intent, postcard, callback); } }); break; case PROVIDER: //這裏省略代碼 case BOARDCAST: case CONTENT_PROVIDER: case FRAGMENT: //這裏省略代碼 case METHOD: case SERVICE: default: return null; } return null; }
//首先經過註解添加下面代碼 @Route(path = "/test/TestActivity") public class TestActivity extends BaseActivity { } //跳轉 ARouter.getInstance().inject("/test/TestActivity");
//存放全部的路由路徑常量 public class ARouterConstant { //跳轉到視頻頁面 public static final String ACTIVITY_VIDEO_VIDEO = "/video/VideoActivity"; //省略部分diamagnetic } //存放全部的路由跳轉,工具類 public class ARouterUtils { /** * 簡單的跳轉頁面 * @param string string目標界面對應的路徑 */ public static void navigation(String string){ if (string==null){ return; } ARouter.getInstance().build(string).navigation(); } } //調用 @Route(path = ARouterConstant.ACTIVITY_VIDEO_VIDEO) public class VideoActivity extends BaseActivity { } ARouterUtils.navigation(ARouterConstant.ACTIVITY_VIDEO_VIDEO);