Android Studio 使用另一个 AAR 文件和里面的 jar 创建 AAR
Android Studio Create AAR using another AAR file and jar inside
我正在使用另一个 aar 和 jar 文件依赖项创建 AAR 文件。我已成功创建 .aar 发布文件。
然后,我将新的 AAR 文件导入到示例项目中。该项目 运行 很好。当要访问那个 aar 和 jar 类 意思时,它显示 NoClassDefFound 错误。
注意:首先我想知道,到目前为止,AAR 是否可以包含在另一个 AAR 中。谁能帮我解决这个新问题?
我也提到了这个 link 也 。它说传递=真。但是,不明白在哪里使用该标志。在第三方使用应用程序或在 AAR 项目依赖项中创建 AAR 时。
提前致谢。
我的迷你项目Gradle文件:
迷你项目,仅转换为.AAR 文件。然后,这个文件只会使用另一个 NewProject
迷你项目Build.gradle文件
/*
This would be enabled for development purpose and to debug and check the same
*/
apply plugin: 'com.android.application'
/*
This would be enabled for exporting as aar file
apply plugin: 'com.android.library'
*/
//apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
defaultConfig {
/*
This application id would be used for development purpose and to debug and check the same.
This would be commented when exporting as library
*/
applicationId 'com.pss.pssplayer'
minSdkVersion 18
targetSdkVersion 23
multiDexEnabled true
versionCode 1
versionName "1.0"
}
aaptOptions {
cruncherEnabled = false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile files('libs/ksoap2-android-assembly-3.2.0-jar-with-dependencies.jar')
compile files('libs/secure.jar')
compile(project(':getSubProject')) {
transitive = true
}// this getSubProject also contains one classes jar
}
当您在依赖项中引用 aar 和 jar 时,您可以使用对第一个的引用来编译新的 aar。
但它们没有嵌入到您的 aar 中。相反,使用 "big aar" 的应用程序也首先需要对两者的依赖。
为此,您可以将所有 aar 部署在像 maven 这样的存储库中,告诉 maven "big aar" 首先取决于两者。 (-> pom.xml)
在你的应用程序build.gradle文件中,你可以只在"big aar"和transitive=true
上添加依赖,告诉系统查看依赖的依赖关系。
编辑 :
你至少可以合并罐子。看看这些答案:
gradle - how do I build a jar with a lib dir with other jars in it?
Can Gradle jar multiple projects into one jar?
合并 aar 比较困难,因为您必须合并所有资源、清单等...
使用android-fat-aar gradle插件,超级好用!
我正在使用另一个 aar 和 jar 文件依赖项创建 AAR 文件。我已成功创建 .aar 发布文件。
然后,我将新的 AAR 文件导入到示例项目中。该项目 运行 很好。当要访问那个 aar 和 jar 类 意思时,它显示 NoClassDefFound 错误。
注意:首先我想知道,到目前为止,AAR 是否可以包含在另一个 AAR 中。谁能帮我解决这个新问题?
我也提到了这个 link 也
提前致谢。
我的迷你项目Gradle文件:
迷你项目,仅转换为.AAR 文件。然后,这个文件只会使用另一个 NewProject
迷你项目Build.gradle文件
/*
This would be enabled for development purpose and to debug and check the same
*/
apply plugin: 'com.android.application'
/*
This would be enabled for exporting as aar file
apply plugin: 'com.android.library'
*/
//apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
defaultConfig {
/*
This application id would be used for development purpose and to debug and check the same.
This would be commented when exporting as library
*/
applicationId 'com.pss.pssplayer'
minSdkVersion 18
targetSdkVersion 23
multiDexEnabled true
versionCode 1
versionName "1.0"
}
aaptOptions {
cruncherEnabled = false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile files('libs/ksoap2-android-assembly-3.2.0-jar-with-dependencies.jar')
compile files('libs/secure.jar')
compile(project(':getSubProject')) {
transitive = true
}// this getSubProject also contains one classes jar
}
当您在依赖项中引用 aar 和 jar 时,您可以使用对第一个的引用来编译新的 aar。
但它们没有嵌入到您的 aar 中。相反,使用 "big aar" 的应用程序也首先需要对两者的依赖。
为此,您可以将所有 aar 部署在像 maven 这样的存储库中,告诉 maven "big aar" 首先取决于两者。 (-> pom.xml)
在你的应用程序build.gradle文件中,你可以只在"big aar"和transitive=true
上添加依赖,告诉系统查看依赖的依赖关系。
编辑 :
你至少可以合并罐子。看看这些答案:
gradle - how do I build a jar with a lib dir with other jars in it?
Can Gradle jar multiple projects into one jar?
合并 aar 比较困难,因为您必须合并所有资源、清单等...
使用android-fat-aar gradle插件,超级好用!