【问题标题】:Including external project into Android app将外部项目包含到 Android 应用程序中
【发布时间】:2015-11-20 14:53:45
【问题描述】:

我目前正在尝试将旧项目从 eclipse 移动到 Android Studio。该项目包含一个“核心模块”(包含大量网络内容)、一个 Android 应用程序和一个 Java PC 应用程序,它们都包含相互通信的核心模块。每个应用程序和核心都有自己的存储库。

在使用eclipse应用时,PC应用和核心是同一个工作区中的三个独立eclipse项目,两个应用依赖于核心项目。

我成功地将 Android 应用程序移至 Android Studio,并将核心移至带有 gradle 的 IntelliJ。 我现在尝试告诉 Android Studio 在构建应用程序时编译内核。我的文件结构如下:

GitHub
------\ AndroidApp
----------------\ build.gradle
----------------\ settings.gradle
----------------\ app
---------------------\ build.grale
------\ NetworkCore
----------------\ build.gradle
----------------\ settings.gradle

AndroidApp/build.gradle

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

AndroidApp/settings.gradle

include ':app', 'core'
project(':core').projectDir = new File('../NetworkCore')

AndroidApp/app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "xxxxxxxxxxx"
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile project(':core')
}

NetworkCore/build.gradle

group 'xxxxxxxxxx'
version '1.0-SNAPSHOT'

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

NetworkCore/settings.gradle

rootProject.name = 'xxxxxxx'

问题

Android Studio 将核心检测为模块,并在左侧边栏中正确列出所有文件。但是在编译 Android Studio 时,无法从核心中找到类,有时甚至无法从应用模块中找到类(如 Fragment 类等)。

我做错了什么?提前非常感谢你:)

【问题讨论】:

  • 您是否正确导入了您的模块?你是否在你的安卓应用程序中为核心模块添加了依赖项?为什么添加 testcompile 作为 android 应用程序的依赖项?测试编译依赖于核心 ..make 核心依赖于您的应用

标签: android android-studio intellij-idea gradle


【解决方案1】:

AndroidApp/settings.gradle 文件中是否缺少冒号?

include ':app', ':core'
project(':core').projectDir = new File('../NetworkCore')

【讨论】:

  • 我从这个答案中复制了这个:stackoverflow.com/a/24978161/4021947 我已经尝试过使用冒号和不使用冒号,似乎完全没有区别
  • 也许这个link可以帮助你。
  • 修复了!你是对的,但还有另外两个问题。首先,我必须将 sourceCompatibility = 1.7 添加到 NetworkCore/build.gradle,因为我使用的是与 android 不兼容的 Java 1.8 来构建它,并且我的文件结构中有一个导入错误我没有识别出来......我花了 2几个小时,这太简单了......
  • 很高兴我能帮上忙 :)
猜你喜欢
  • 2015-12-13
  • 2012-05-23
  • 2011-01-04
  • 1970-01-01
  • 1970-01-01
  • 2021-08-24
  • 1970-01-01
  • 1970-01-01
  • 2012-12-03
相关资源
最近更新 更多