我目前正在尝试将旧项目从 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 类等)。
我究竟做错了什么?非常感谢你:)
最佳答案
您的 AndroidApp/settings.gradle
中是否缺少冒号?文件?
include ':app', ':core'
project(':core').projectDir = new File('../NetworkCore')
关于android - 将外部项目包含到 Android 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33829641/