组件化开发遇到的问题

组件化开发遇到的问题

1、Suggestion: add 'tools:replace="android:name"'
app 一起运行时,application重复命名问题

自定义 Application 需要声明在 AndroidManifest.xml 中。其次,每个 Module 都有该清单文件,但是最终的 APK 文件只能包含一个。因此,在构建应用时,Gradle 构建会将所有清单文件合并到一个封装到 APK 的清单文件中。
所以,需要放在application的东西都放在baseApplication中,如必须在不同组件中的Manifest中使用,使用tools:repalce 替代。

合并的优先级是:App Module > Library Module

2、

Aroute使用问题锦囊

1、资源命名重复,引用不正确

在不同moudle下要添加
resourcePrefix "login_"
防止相同文件名出现指向错误 login_activity_main
然后在对应的布局资源文件前面添加
不能同时使用 会报There is no route match the path

2、There is no route match the path,no group

一定要让所有需要ARouter的Moudle中builde.gradle添加annotationProcessor 'com.alibaba:arouter-compiler:1.1.4'
并且在主APP的Moudle中关联所有需要的模块,否则会提示There is no route match the path,no group

组件化Butterknife使用问题锦囊

1、在library中使用R2

(1)在主程序的build.gradle中

 dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // 添加的部分
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
}

(2)在对应moudle的build.gradle

compile "com.jakewharton:butterknife:$rootProject.butterknife"
annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.butterknife"

(3)在使用到butterknife的library的gradle中

 apply plugin: 'com.android.library'
 apply plugin: 'com.jakewharton.butterknife'

(4)R变为R2,swicth case 改为if else

 @OnClick({R2.id.xxx, R2.id.xxx, R2.id.xxx, R2.id.xxx, R2.id.xxx})
    public void onViewClicked(View view) {
        int i = view.getId();
        if (i == R.id.xxx) {
        } else if (i == R.id.xxx) {
        } else if (i == R.id.xxx) {
        } else if (i == R.id.xxx) {
        } else if (i == R.id.xxx) {
        }
    }

猜你喜欢

转载自blog.csdn.net/weixin_34227447/article/details/86906755
今日推荐