【问题标题】:Android application with Android library project as external module以 Android 库项目作为外部模块的 Android 应用程序
【发布时间】:2014-12-28 00:33:38
【问题描述】:

在我的 Android 应用程序项目中,我想使用 https://github.com/Bearded-Hen/Android-Bootstrap/tree/master/AndroidBootstrap 作为依赖项(我使用 Android Studio 0.8.8)。

这是我的 settings.gradle

include ':gui', ':client', ':Android-Bootstrap'
project(':Android-Bootstrap').projectDir=new File('/abs/path/to/Android-Bootstrap/AndroidBootstrap')

还有我的 gui/build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.13.3'
    }
}
apply plugin: 'com.android.application'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
    }

...
skipped
...
}

dependencies {
    ...skipped...
    compile 'com.android.support:appcompat-v7:19.1.0'
    ...skipped...
    compile project(':client')
    compile project(':AndroidBootstrap')
}

当我同步同步时,我得到::

Error:(1, 0) Plugin with id 'android-library' not found.

如果我删除

project(':Android-Bootstrap').projectDir=new File('/abs/path/to/Android-Bootstrap/AndroidBootstrap')

我明白了

Error:(44, 0) Project with path ':AndroidBootstrap' could not be found in project ':gui'.

如果我将https://github.com/Bearded-Hen/Android-Bootstrap/blob/master/AndroidBootstrap/build.gradle 更改为

apply plugin: 'com.android.library'

我明白了

Error:(1, 0) Plugin with id 'com.android.library' not found.

如果我添加到https://github.com/Bearded-Hen/Android-Bootstrap/blob/master/AndroidBootstrap/build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.13.3'
    }
}

我明白了

Error:(44, 0) Project with path ':AndroidBootstrap' could not be found in project ':gui'.

如何解决?我希望这个模块是外部的,没有导入和复制到主项目中。为什么修复 gradle 插件依赖会导致找不到路径的问题?

【问题讨论】:

  • 尝试使用包含 ':AndroidBootstrap' 的 'settings.gradle'

标签: android gradle android-studio android-gradle-plugin android-library


【解决方案1】:

在settings.gradle中修复如下:

include ':gui', ':client', ':AndroidBootstrap'
project(':AndroidBootstrap').projectDir=new File('/abs/path/to/Android-Bootstrap/AndroidBootstrap')

请注意,Android-Bootstrap 已替换为 AndroidBootstrap(不是破折号)

并且在root build.gradle (./build.gradle)

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.13.3'
    }
}

它将覆盖(设置)AndroidBootstrap 中的构建脚本依赖项。

AndroidBootstrap 本身不需要做任何更改。

【讨论】:

    猜你喜欢
    • 2019-08-03
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多