Skip to content

plugin和host能在一个工程里面一起开发吗 #43

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

Closed
whosmyqueen opened this issue Jul 1, 2017 · 9 comments
Closed

plugin和host能在一个工程里面一起开发吗 #43

whosmyqueen opened this issue Jul 1, 2017 · 9 comments
Labels

Comments

@whosmyqueen
Copy link

whosmyqueen commented Jul 1, 2017

@jiongxuan 我在同一个工程里面试了下,会报错:
root build.gradle:
`// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
maven {
url "https://dl.bintray.com/qihoo360/replugin"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.qihoo360.replugin:replugin-host-gradle:2.1.0'
classpath 'com.qihoo360.replugin:replugin-plugin-gradle:2.1.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "https://dl.bintray.com/qihoo360/replugin"
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
**host app build.gradle:**apply plugin: 'com.android.application'
apply plugin: 'replugin-host-gradle'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.zhph.zhyq"
minSdkVersion 14
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 fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.qihoo360.replugin:replugin-host-lib:2.1.0'
}
**plugin home build.gradle:**apply plugin: 'com.android.application'
apply plugin: 'replugin-plugin-gradle'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"

defaultConfig {
    applicationId "com.zhph.home"
    minSdkVersion 14
    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 fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.qihoo360.replugin:replugin-plugin-lib:2.1.0'
}
**Error message:**Error:(2, 0) Failed to apply plugin [id 'replugin-plugin-gradle']
Open File`

@jiongxuan
Copy link
Contributor

我们没有尝试把两个相对独立的工程(插件和主程序)放到一起。
因为在我们看来,插件就是插件,主程序就是主程序,这两个本来就是两个APK而已

不过我们有的App,是将插件和宿主放到同一个工程目录下(本质上仍然是两个工程),这样只需打开一个根目录,就能打开主程序 + 插件工程了。您可以尝试采用这个办法。

@whosmyqueen
Copy link
Author

@jiongxuan 我的意思是,我想把每个大业务提成插件,公共库也提成插件,这样支持吗

@jiongxuan
Copy link
Contributor

我们是支持的。手机卫士目前每个大业务都是插件,也有一些公共库(如WebView等)。只不过将原业务抽离成插件的话,大多不是一两句话就能解决的,需要做一些调整。

@whosmyqueen
Copy link
Author

@jiongxuan 能在demo里面写下不

@ikakaxi
Copy link

ikakaxi commented Jul 2, 2017

@whosmyqueen 你的意思是把com.android.library也做成插件吗?

@jiongxuan
Copy link
Contributor

jiongxuan commented Jul 2, 2017

@whosmyqueen 我们的Demo目前有一些常见的交互方式(例如四大组件的调用等)。实际上,RePlugin还有很多其它有趣的耦合方式,以后我们会补充到Demo中。

只不过,因为各业务的实际情况不同,所以没法写出各种不同场景下的Demo,只能把一些普适性的写出来,您可以参考,并尝试用于自己的项目中(可能会有变体,就像解题那样,需要多个步骤才能解决)。

此外,有的业务其耦合就非常深(例如首页和各子模块、基础插件等),有的耦合就很少(如我们的桌面插件和悬浮窗插件,这俩业务关联就不大)。两者不能一概而论,但我们都是支持的。

不知道这样回答是否解开了您的疑惑?

@Hiram-Y
Copy link

Hiram-Y commented Jul 3, 2017

宿主更插件都有用到一个公共库,这个公共库能够不打包在插件里,减少插件的大小,直接放在宿主里呢? @jiongxuan

@jiongxuan
Copy link
Contributor

当然可以,目前“手机助手”在接入RePlugin时,就是这么做的。

他们有一个换肤View,只要该View不被混淆,则插件可以直接使用它,而无需额外修改。

但如果直接调用View中的自定义方法(例如CustomView中的某个方法),出于稳定性考虑(怕插件更新后,直接调用会出现问题),故需要反射,而View中的方法可以直接调用,不受影响。

@jiongxuan
Copy link
Contributor

我们近期会补一个Sample,主要针对直接使用公共库(代码)的部分,欢迎参考。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants