【问题标题】:Compile multiple modules in Android Gradle Dependency在 Android Gradle Dependency 中编译多个模块
【发布时间】:2015-09-09 17:05:08
【问题描述】:

我正在尝试使用 andEngine 及其physicsBox2D 扩展创建一个应用程序。为此,我必须添加 2 个模块,然后在我的应用程序中编译 - andEngineandEngine PhysicsBox2D。我有以下 Gradle 代码 -

apply plugin: 'com.android.model.application'

model {

android {
    compileSdkVersion = 22
    buildToolsVersion = "22.0.1"

    defaultConfig.with {
        applicationId = "com.sample.practice"
        minSdkVersion.apiLevel = 9
        targetSdkVersion.apiLevel = 22
        versionCode = 1
        versionName = "1.0"
    }
}

android.buildTypes {
    release {
        minifyEnabled = false
        proguardFiles += file('proguard-rules.pro')
    }
}
}

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

但是这段代码在运行时给出了这个错误 - ...java.exe finished with non zero exit value 2

如果我从 Gradle 中删除 compile project(':andEnginePhysicsBox2D'),应用程序运行正常。 但是这段代码对于应用程序的工作很重要。有什么想法可以在 Gradle 的依赖项中同时实现 andEngineandEngine PhysicsBox2D 吗?

感谢

PS -我正在使用带有 Android Studio 1.3 的实验性 Android Gradle Plugin V.0.2 来处理一些 NDK 内容。

【问题讨论】:

    标签: android android-studio gradle andengine


    【解决方案1】:

    Box2d 扩展需要 AndEngine 模块作为其依赖项,您的项目也需要它们作为其依赖项。还应该注意的是,依赖关系的顺序很重要

    所以你应该确保你已经配置了三个 gradle 文件,如下所示。

    • 您的游戏 gradle 文件:

      dependencies {
          compile fileTree(dir: 'libs', include: ['*.jar'])
          compile project(':andEngine')
          compile project(':andEnginePhysicsBox2D')
      }
      
    • AndEngine gradle 文件:

      它没有任何依赖关系。

    • Box2d 扩展 gradle 文件:

      dependencies {
          compile project(':andEngine')
      }
      

    【讨论】:

      【解决方案2】:

      解决了这个问题-

      1) andEngine 中存在一些问题,解决了这些错误。

      2) 在Gradle 中启用multiDex

      【讨论】:

        【解决方案3】:

        我使用的是 Android Studio 1.2.2 以下脚本适用于我。

        看看这是否有帮助?

        apply plugin: 'com.android.application'
        
        android {
            compileSdkVersion 22
            buildToolsVersion "22.0.1"
            defaultConfig {
                applicationId 'com.xxxx.yyy'
                minSdkVersion 8
                targetSdkVersion 22
                versionCode 1
                versionName "1.0"
            }
            buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                }
            }
            sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/gfx/'] } }
            productFlavors {
            }
        }
        
        dependencies {
            compile fileTree(include: ['*.jar'], dir: 'libs')
            compile 'com.android.support:appcompat-v7:22.1.1'
            compile project(':andengine')
            compile project(':andenginebox2dextension')
        }
        

        【讨论】:

          猜你喜欢
          • 2022-08-03
          • 1970-01-01
          • 1970-01-01
          • 2019-05-09
          • 1970-01-01
          • 2018-09-04
          • 2019-11-24
          • 1970-01-01
          • 2012-09-03
          相关资源
          最近更新 更多