Android Aar文件与Google应用程序引擎模块具有依赖关系
我的(Android Studio)项目有两个模块:一个Android库(app)模块和一个Google后端模块。应用程序模块访问后端。在我的gradle dependencies(应用程序)中,我有: 我想在其他项目中使用应用程序库,所以我尝试了a)将其导出到aar库,b)将其导出到jar库。它在编译时工作。我可以使用应用程序模块的所有类。但是当运行这个应用程序时,它给了我一个错误,它没有找到作为应用程序和后端模块(作为后端的一部分)之间接口的类 有人知道我怎样才能让它工作吗 编辑:以下是完整的gradle文件: 图书馆应用程序:Android Aar文件与Google应用程序引擎模块具有依赖关系,android,google-app-engine,gradle,android-studio,aar,Android,Google App Engine,Gradle,Android Studio,Aar,我的(Android Studio)项目有两个模块:一个Android库(app)模块和一个Google后端模块。应用程序模块访问后端。在我的gradle dependencies(应用程序)中,我有: 我想在其他项目中使用应用程序库,所以我尝试了a)将其导出到aar库,b)将其导出到jar库。它在编译时工作。我可以使用应用程序模块的所有类。但是当运行这个应用程序时,它给了我一个错误,它没有找到作为应用程序和后端模块(作为后端的一部分)之间接口的类 有人知道我怎样才能让它工作吗 编辑:以下是完整
apply plugin: 'android-library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.cluedup.voicecontrols"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs', '../backend/libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':Backend', configuration: 'android-endpoints')
compile ('com.google.android.gms:play-services-wearable:6.1.71') {
exclude module: 'support-v4'
}
}
导入应用程序
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.cluedup.voicecontrols.sample"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.google.android.gms:play-services-wearable:6.1.71') {exclude module: 'support-v4'}
compile(name:'app-debug', ext:'aar'){transitive=true}
}
以下是对我有用的东西——但对我来说,这似乎是一个黑客!因此,如果有人有更好的解决方案,我仍然会很高兴听到关于 步骤1:创建后端模块的jar。实际上,后端的jar是在sonatype中央存储库中发布整个应用程序时产生的副产品。我按照这个例子()来准备上传 因此,我在../backend/build/libs目录中找到了后端的jar文件 步骤2:删除应用程序对后端模块的依赖关系,并将其替换为对已创建jar文件的依赖关系
// DO NOT USE compile project(path: ':Backend', configuration: 'android-endpoints')
compile(name:'Backend-0.0.2', ext:'jar'){transitive=true}
步骤3:使用gradlew Assembly创建应用程序的aar文件
步骤4:在导入项目中添加后端的jar和应用程序的aar作为依赖项
compile(name:'app', ext:'aar'){transitive=true}
compile(name:'Backend-0.0.2', ext:'jar'){transitive=true}
你用Proguard吗?显示另一个项目的依赖项配置。我使用proguard的方式与您在上面编辑的部分中看到的方式相同。proguard可能会剥离此类,但我发现您有
runProguard false
,因此这应该不是问题。我认为你的导入可能是错误的。您应该尝试使用端点类的包名,而不是库应用程序的aar。请记住,生成的云端点位于本地maven存储库中。对于Linux,它默认为.m2
。您的import my看起来是这样的:compile“端点的包名:端点名:版本”
我从哪里获得enpoint的版本?由于它不是Android模块,因此gradle-file中没有Android部分。如果您不知道确切的版本名,可以使用+
compile“端点的包名:endpoint name:+
表示将使用最新版本
// DO NOT USE compile project(path: ':Backend', configuration: 'android-endpoints')
compile(name:'Backend-0.0.2', ext:'jar'){transitive=true}
compile(name:'app', ext:'aar'){transitive=true}
compile(name:'Backend-0.0.2', ext:'jar'){transitive=true}