【问题标题】:Include apk module as dependency in android studio在 android studio 中包含 apk 模块作为依赖项
【发布时间】:2015-08-03 12:21:00
【问题描述】:

我的项目中有两个模块:

  1. 应用程序
  2. app_list

两个模块都有 java 和 res。 app_list 有一些我想在app 发起的活动。

在 Eclipse 中,我将 app_list 作为依赖库,并且能够启动 app_list 的活动。在 Android Studio 中,当我添加 app_list 作为依赖项时,它说:

"Error:A problem occurred configuring project ':app'.
> Dependency NewMathBuzz:app_list:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: <home>/NewMathBuzz/app_list/build/outputs/apk/app_list-release-unsigned.apk
"

app > build.gradle 如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.mass.mathbuzz"
        minSdkVersion 7
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(':app_list')
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

app_list > build.gradle 如下:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 7
        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.mcxiaoke.volley:library:1.0.18'
    compile 'com.android.support:appcompat-v7:22.0.0'
}

有人可以帮我解决这个问题吗?

【问题讨论】:

  • apk 文件不能是依赖项。你做错了什么
  • @Vlad 那么我该怎么做呢,基本上 app_list 有我想包含在许多应用程序中的通用 Activity,所以我正在制作广告模块
  • 显示你的 build.gradle
  • @VladMatvienko 我刚刚更新,你能看到吗
  • 好的,尝试将apply plugin: 'com.android.application' 中的app_list build.gradle 更改为apply plugin: 'com.android.library'

标签: android eclipse android-studio


【解决方案1】:

一切都很好,

基本上当我把app_list.gradle改成

apply plugin: 'com.android.application'apply plugin: 'com.android.library' 并从 app_list.gradle 中删除 applicationId 它编译并生成了 apk,但我遇到了运行时错误,这是因为 app 和 app_list 都具有相同的资源 main_activity 所以 R.java 没有 main_activity res 的 app_list 所以它给出了非法参数错误。当我将 main_activity 的名称更改为某个唯一名称时,它解决了问题

【讨论】:

  • 这为我解决了。在我想用作库的项目的 gradle 中,我将其设置为 apply plugin: 'com.android.application' 而不是“库”。谢谢。
猜你喜欢
  • 2014-02-05
  • 1970-01-01
  • 2018-03-13
  • 1970-01-01
  • 2015-07-03
  • 1970-01-01
  • 2013-04-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多