gpt4 book ai didi

android - 依赖于 Google-App-Engine 模块的 Aar 文件

转载 作者:行者123 更新时间:2023-12-03 06:18:58 25 4
gpt4 key购买 nike

我的 (Android Studio) 项目有两个模块:一个 Android-Library (app) 模块和一个 Google 后端模块。 app 模块访问后端。在我的 gradle 依赖项(应用程序)中,我有:

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'
}

我想在其他项目中使用应用程序库,所以我尝试 a) 将其导出到 aar-library 和 b) 将其导出到 jar-library。它在编译期间工作。我可以使用应用程序模块的所有类。但是在运行这个应用程序时,它给了我一个错误,它没有找到作为应用程序和后端模块之间的接口(interface)的类(作为后端的一部分)。
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/cluedup/voicecontrols/backend/apiVoiceForm/model/VoiceFormBean;

有人知道我怎样才能让它工作吗?

编辑:这是完整的 gradle 文件:

图书馆-应用程序:
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}
}

最佳答案

这对我有用——不过,这对我来说似乎是个技巧!因此,如果有人有更好的解决方案,我仍然会很高兴听到

第一步:创建一个后端模块的 jar。实际上,当试图在 sonatype 中央存储库中发布整个应用程序时,后端的 jar 是作为副产品产生的。我按照这个示例 (http://gmariotti.blogspot.de/2013/09/publish-aar-file-to-maven-central-with.html) 为上传做准备。

结果,我在 ../backend/build/libs 目录下找到了一个后端的 jar-file。

第二步:删除应用程序对后端模块的依赖,并将其替换为对创建的 jar 文件的依赖

// DO NOT USE compile project(path: ':Backend', configuration: 'android-endpoints')
compile(name:'Backend-0.0.2', ext:'jar'){transitive=true}

第三步:使用 gradlew assemble 创建应用程序的 aar 文件

第四步:在导入项目中添加后端的jar和应用的aar作为依赖项
compile(name:'app', ext:'aar'){transitive=true}
compile(name:'Backend-0.0.2', ext:'jar'){transitive=true}

关于android - 依赖于 Google-App-Engine 模块的 Aar 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27756750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com