以下是在另一个应用程序中添加项目作为模块/库时可能遇到的困难的答案。
跟随
this video tutorial
以下是您需要考虑的几点。
-
更改构建的第一行。gradle(库)从“应用插件:com.android.application”到“应用插件:com.android.library”
-
从生成中删除applicationId。gradle(图书馆)
-
确保构建。gradle(应用程序)和build。gradle(库)应该完全相同。
如下所示
建筑gradle(应用程序)
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.xyz.xyzxyz"
minSdkVersion 7
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':openCamera')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
建筑gradle(图书馆)
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.android.support:appcompat-v7:22.0.0'
}
-
如果应用程序和库模块都具有MainActivity和activity_main。xml文件,然后在应用程序或库中进行更改。因为您可能会得到rumTime错误,如#40(行号)处的二进制xml错误等。
-
您的android studio版本和项目级gradle依赖项应该具有相同的版本。比如,如果你的studio版本是2.3.1,那么Dependency块应该有“classpath”com.android.tools.build:gradle:2.3.1”
-
最后,从库的清单文件中删除库的mainActivity的标记。代码如下所示。如果你不删除或评论它,那么两个启动器将出现在你的项目中,它将创建两个图标。
<!-- Comment or delete tag to avoid two launchers in your application -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>