6月30號360新開源了一個插件開發框架RePlugin,然而文檔不全,根據360的文檔你做出來的項目一編譯就是一大堆錯誤,因為很多需要配置的東西在360的插件開發文檔里根本就沒有,我在這里記錄一下給需要的人
1.https://github.com/Qihoo360/RePlugin/wiki/主程序接入指南
在這里的第一步 <strong>[添加 RePlugin Host Gradle 依賴]</strong>之前還有一步,文檔并沒有寫,就是在項目根目錄的 <strong>build.gradle</strong>中的<strong>buildscript</strong>和<strong>allprojects</strong>的下面添加
maven {
url "https://dl.bintray.com/qihoo360/replugin"
}
否則框架所需要的資源根本找不到,完整配置類似如下代碼:
buildscript {
repositories {
jcenter()
maven {
url "https://dl.bintray.com/qihoo360/replugin"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.qihoo360.replugin:replugin-host-gradle:2.1.0'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://dl.bintray.com/qihoo360/replugin"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2.還是在https://github.com/Qihoo360/RePlugin/wiki/主程序接入指南 還有一步也沒有寫,必須在你的宿主Module的assets下面增加plugins文件夾,即使里面沒有插件文件也要創建該文件夾,否則會出現以下錯誤
Error:Execution failed for task ':app:processDebugResources'.
> /Users/xxx/Documents/WorkSpace/WorkSpaceAndroid/TestRePlugin/app/src/main/assets/plugins
添加了這個文件夾后編譯會自動出現plugins-builtin.json文件
3.LocalBroadcastManager類找不到的錯誤
你的程序需要添加v4包,因為插件框架內部使用到了v4包的LocalBroadcastManager類
4.Failed to apply plugin [id 'replugin-plugin-gradle']
在https://github.com/Qihoo360/RePlugin/wiki/插件接入指南 這里需要注意這幾個地方:
4.1.1 gradle版本必須是gradle-2.14.1-all,如果編譯出現下圖這樣的錯誤
image.png
那么你需要修改你的工程中的gradle->warpper->gradle-wrapper.properties文件的distributionUrl為https://services.gradle.org/distributions/gradle-2.14.1-all.zip
比如下面這樣的配置
#Sun Jul 02 15:33:02 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
4.1.2 apply plugin: 'replugin-plugin-gradle'這句話要放在build.gradle文件的末尾處
例如下面這樣
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.test.replugin.plugin"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:support-v4:25.3.0'
compile 'com.qihoo360.replugin:replugin-plugin-lib:2.1.0'
}
apply plugin: 'replugin-plugin-gradle'
<small>參考問題:https://github.com/Qihoo360/RePlugin/issues/53</small>