1.主项目中import需要导入项目的app模块;
2.修改该module中build.gradle里的com.android.application为com.android.library;
3.删除该module的applicationId;
4.File->打开工程结构,导入module,若没有,则在setting.gradle中手动添加后再导入;
5.由于ugsv中build.gradle里面的配置引入的项目级的build.gradle,则将小视频的工程级的build.gralde里ext的内容直接复制到自己项目中的工程级的build.gralde里;
6.此时报错:
Unable to resolve dependency for ':app@debug/compileClasspath': Could not find :LiteAVSDK_Professional
解决:
将ugsv这一module中的两个so文件拷贝到app这一module中的src/main/jniLibs文件夹下,并在项目级的build.gradle中的allprojects下repositories中添加:
flatDir {
dirs 'src/main/jniLibs'
}
7.Try Again,此时报错:
Android dependency 'com.android.support:multidex' has different version for the compile (1.0.0) and runtime (1.0.2) classpath. You should manually set the same version via DependencyResolution
解决:
方法数65k限制,在app的build.gradle中的defaultConfig中加入:
multiDexEnabled = true
8.Try Again,此时报错:
AAPT2 error: check logs for details
主要是 将项目级中build.gradle的classpath的gradle版本降为2.2.3;
并将app中build.gradle中的所有implitetion改为compile;
9.Try Again,此时报错:
Cause: buildToolsVersion is not specified.
在app的build.gradle中添加buidToolsVersion;
10.Try Again,此时报错:
The versions of the Android Gradle plugin and Gradle are not compatible.
Please do one of the following:- Update your plugin to version 2.4. This will require changes to build.gradle due to API changes.
解决:
修改项目级的build.gradle为3.0.0,将两个module中的
compile,buildToolds以及targetSdkVersion都保持一致;
11.此时报错
compile 'com.android.support:appcompat-v7:23.2.1'
解决:
将两个module中appcompat,design,recyclerview的版本号保持一致,其取决于compileSdkVersion;
参开该文章
12.rebuild,此时报错,主要是其他module中不能用switch选择语句;
13.run,报错:
com.android.builder.merge.DuplicateRelativeFileException: More than one file was found with OS independent path 'lib/armeabi/libtraeimp-rtmp-armeabi.so'
解决:
app这一module的build.gradle中,加入以下代码,即排除重复的文件:
packagingOptions {
exclude 'lib/armeabi/libtraeimp-rtmp-armeabi.so'
exclude 'lib/armeabi-v7a/libtraeimp-rtmp-armeabi-v7a.so'
}
14.run,由于手机已安装小视频app,AndroidManifest里面provider标签的authorities与导入module的相同,所以需修改;
15.再run,会崩溃,找不到module的application中的方法;
解决:
由于module不再是app,所以将导入的module中的AndroidManifest里的application属性全部去掉;
16.再run,到导入的module里的内容时,崩溃:
java.lang.UnsatisfiedLinkError: No implementation found
解决:
app的build.gradle里的buildTypes加入abiFilters,参照该文章;
此时便已成功导入module并运行了。
参考:导入Android工程作为Library Module流程及问题集