android - 将依赖项添加到模块 - 外部库错误

标签 android build.gradle

我创建了一个外部库,希望将其开源。我将它作为模块导入没有问题。

我必须在导入后解决这个问题: enter image description here

添加依赖是我想做的。我不想将其移动到 :app。

当我添加依赖项时,问题就消失了。导入引用了正确的文件。在构建时我遇到了这个问题: enter image description here

我认为解决方案必须是在外部库的 build.gradle 文件中引用 java 文件,但我找不到任何好的示例,甚至无法证明这可以解决问题。

library是模块名。

提前致谢。

编辑: 应用程序的 build.gradle

apply plugin: 'com.android.application'

android {
  compileSdkVersion 22
  buildToolsVersion "23.0.0 rc3"

  defaultConfig {
    applicationId "com.weaverprojects.toundertest1"
    minSdkVersion 21
    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.google.android.gms:play-services-gcm:7.5.0'
}

库的build.gradle

apply plugin: 'com.android.library'
android {
  compileSdkVersion 22
  buildToolsVersion "23.0.0 rc3"

  defaultConfig {
    minSdkVersion 19
    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.android.support:appcompat-v7:22.2.1'
  compile 'com.google.android.gms:play-services-gcm:7.5.0'
 }

设置.gradle

include ':app', ':library'

最佳答案

假设您的 library 作为自己的项目存在,并且它相对于 main 项目的顶级文件夹的路径是 ../mylibs/library/我认为您的 settings.gradle 应该更改如下:

project(':library').projectDir = new File('../mylibs/library/');

以下内容需要进入您的main/app/build.gradle 文件的依赖项部分(我认为这是您问题中的第一个代码转储)。

compile project(':library')

顺便说一句,请考虑将 :library 重命名为其他名称(这不是问题的根源,但几个月后查看名称时可能会造成混淆)

关于android - 将依赖项添加到模块 - 外部库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32686251/

相关文章:

android - viewPagerIndicator :Error:Artifact 'com.viewpagerindicator:library:2.4.1:library.aar' not found

android - androidstudio2多种APK

java - 从sqlite数据库Android检索数据时捕获异常

java - 如何在 SQLite 数据库中保存 getIntent() 值?

android - Gradle 在我的项目中包含第 3 方依赖项

android - 你如何结合多种 gradle 口味或排除一种?

android - 使用 Android HTTP Post 将文件上传到 MySQL 数据库

Android New Image 文件名末尾有奇怪的数字

javascript - react 原生 "Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)"

android - 如何处理错误 : failed linking references