1. 程式人生 > >將Android專案作為module匯入到主專案中

將Android專案作為module匯入到主專案中

匯入module流程:

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 ':[email protected]/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:<ul><li>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並運行了。