####一、描述
Small插件化的使用,当前small没有支持3.0,还是支持之前的2.3.3,所以不要升上去用. Small
####二、使用
使用方法就是官方提供的方法,按他所说明的步骤走下去就ok
https://github.com/wequick/Small/tree/master/Android
- 打开路径的方式:
//打开Detail页面,从app.home页面跳转
Small.openUri("detail?from=app.home", view.getContext());
复制代码
- 要跳转插件fragment的时候,需要注意,插件的名称必须是MainFragment,他只识别MainFragment,不然跳转会找不到。
Small.createObject("fragment-v4", "fragment名称", MainActivity.this)
复制代码
####三、编译步骤
全部都重新编译一下,按以下的步骤执行
./gradlew buildLib -q //编译lib的module
./gradlew buildBundle -q //编译bundle
./gradlew small //展示全部的bundle说明
复制代码
单独编译某个,就不用全部bundle都编译
./gradlew -p web.about assembleRelease
复制代码
提供一段项目根目录的build.gradle代码,里面指定2.3.0,也执行了所有的bundle的版本
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
// mavenLocal()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'net.wequick.tools.build:gradle-small:1.3.0-beta3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
// mavenLocal()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'net.wequick.small'
small {
buildToAssets = false
android {
compileSdkVersion = 26
buildToolsVersion = "25.0.2"
supportVersion = "25.1.0"
}
}
复制代码
####四、遇到的问题
注意,如果引用lib的时候,运行会报错,请先检查你的lib有没有在App的bundle.json里面声明,如果没有声明的话,有时候会出问题的。
####1. 在引用了lib库里的类时,报错类找不到,这是因为在bundle.json里面没有指定对这个lib的包名,包名必须和其他bundle的包名相似。类似下面的
//都必须是lb.ehome.com开头的,后面的随意,可能他查找就是按这个规则查找的。
{
"uri": "lib.utils",
"pkg": "lb.ehome.com.lib.utils"
},
{
"uri": "main",
"pkg": "lb.ehome.com.app.main"
}
复制代码
####2 某个bundle使用了databinding,编译的时候,报错
解决:这个原因可能是因为你宿主的build.gradle没有加入下面的申明,加上就可以了
dataBinding {
enabled true
}
复制代码
####3 build lib的时候,报错
./gradlew buildLib -q
[Small] building library 1 of 3 - app (0x7f)
[Small] building library 2 of 3 - lib.style (0x79)
[lib.style] split library res files... [ OK ]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':lib.style:processReleaseResources'.
> No support deleting resources on lib.* now
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
复制代码
解决: 这个错误说明你的lib模块下的public.txt曾因某次编译存在了资源A,但是第二次编译资源A不见了。
请不要做这种拷贝到宿主。如果宿主有这些资源,lib模块会忽略它们。
你现在可以做的是:
删除public.txt,全部重编一次:cleanLib, buildLib, cleanBundle, buildBundle 检查public.txt中已经存在的资源,删除宿主中的那些拷贝 需要注意的是,在生产环境中,(1)意味着可能要更新全部插件。
####4. 报错 You need to use a Theme.AppCompat theme (or descendant) with this activity 解决: 我尝试修改了 lib.style 中 values/styles.xml 和 values-v21/styles.xml 的相关内容后,Sample 工程可以正常运行了。
具体结果如下:
###values/styles.xml###
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar" parent="AppTheme.Base">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
###values-v21/styles.xml###
<style name="AppTheme.NoActionBar" parent="AppTheme.Base">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
复制代码
相应地所有引用的 lib.style 的插件修改到新的 theme 名称即可。
####5. 怎样判断是否 Debug 模式
/**
* app 是否 debug 模式
*
* @param context
*/
public static boolean isDebug(Context context) {
if (isDebug == null) {
isDebug = context.getApplicationInfo() != null &&
(context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
return isDebug;
}
复制代码
- 加入aar文件的时候,导入失败,我在app+stub的lib加入了aar,其他module都会报这个错误
解决:每个Moudle的build.gradle加入下面的代码。直接指定加载app+stub的libs目录的aar。
//加入的代码
repositories {
flatDir {
dirs project(':app+stub').file('libs')
}
}
//下面的不需要
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile(name: 'xxx-debug', ext: 'aar')
compile(name: 'xxx-sit-debug', ext: 'aar')
}
复制代码
- 编译不通过,uses-sdk:minSdkVersion 15 cannot be smaller than version 21 declared in library
解决:修改所有的module的build.gradle,minSdkVersion都改成16
- om.android.dex.DexException: Multiple dex files define Landroid/support/multidex/BuildConfig;
解决:在build.gradle文件下加入下面的代码
android {
defaultConfig {
multiDexEnabled true
}
}
复制代码
- MultiDex.class
解决:添加下面的到build.gradle中
compile 'com.android.support:multidex:1.0.1'
复制代码
###五 学习网站 http://www.jianshu.com/p/c696acb74bd2 http://code.wequick.net/Small/cn/home http://www.jianshu.com/p/07f88d4924db