在Android Studio中使用源依赖项独立运行模块(Intellij?)

时间:2015-03-25 22:23:21

标签: java android intellij-idea android-studio

我正在使用Android工作室,但这可能是一般的Intellij问题(我以前习惯了eclipse)。这似乎应该是超级简单的,但我无法弄明白。

我希望能够独立地在我的项目中运行任何一个模块,这是我理解模块的目的。到目前为止,当我想从我的" app"模块在我的" testmodule"模块。在我尝试构建模块之前,Android Studio允许我导入我需要的代码而没有任何问题。然后我得到了预期的"包找不到"错误。那么我尝试在我的" testmodule"中添加它。的build.gradle:

main.java.srcDirs '../app/src/main/java'

这导致我的" app"中的两个包导入语句模块失败。其中一个失败的包是在我的" app"中定义的包。清单和另一个在我的" app"的build.gradle

sourceSets {
    main.java.srcDirs += '../../connectorAPI/trunk/src'
}

我还试图让一个模块依赖于另一个模块,但是从我在堆栈溢出中读到的(以及模糊的Android Studio错误),一个模块必须是库文件。这显然不起作用,因为我希望能够运行。我希望只是复制我需要的代码但是我需要在版本控制中每次都更改它,这是一场噩梦。

在eclipse中,您所要做的就是右键单击并链接源代码。我无法想象这是不可能的,甚至是不同寻常的,所以我一定要错过一些简单的事情......有人可以帮帮我吗?

build.gradle testmodule

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.XXXXX.testmodule"
        minSdkVersion 15
        targetSdkVersion 21
        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:21.0.3'
    compile 'com.google.android.gms:play-services:+'
}

build.gradle app

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "com.XX.XXX.XXX.XXX"
        minSdkVersion 15
        targetSdkVersion 19
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    packagingOptions {
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
    sourceSets {
        main.java.srcDirs += '../../connectorAPI/trunk/src'
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.google.android.gms:play-services:+'
    // Add the ArcGIS Android 10.2.5 API
    compile 'com.esri.arcgis.android:arcgis-android:10.2.5'
    compile 'com.googlecode.json-simple:json-simple:1.1'
}

1 个答案:

答案 0 :(得分:0)

我可能要迟几年了,但是我要做的是:将两个模块都声明为库,并创建另外两个模块作为应用程序。然后,您可以轻松导入两个库,同时又拥有两个应用程序(如果需要)。

对于将出现的重复依赖问题,您可以分别在build.gradle中添加一个exclude语句。