2013-08-17 54 views

回答

4

這是整個教程如何使用Android Studio和Gradle使用AndEngine和PhysicsBox2D擴展。只要gradle這個不支持我使用的是這裏所描述的黑客本地庫Android Studio Gradle with native libs error

我的項目結構是:
- ProjectRoot
- 的build.gradle
- settings.gradle
- MainProject
- SRC
- 資源
- AIDL
- 模塊
- AndEngine
--- SRC
---水庫
---庫
---- libs.jar
---的build.gradle
- PhysicBox2D
--- SRC
---水庫
- - 庫
---- libs.jar
---的build.gradle
---在這兩個AndEngi settings.gradle

ne和PhysicsBox2D我把文件夾armeabi,armeabi-v7等放到lib文件夾中,然後壓縮它並重新命名爲libs.jar。這在我上面給出的鏈接中有描述。

我的主要settings.gradle文件看起來像這樣

include 'Modules:AndEngine' 
include 'Modules:PhysicBox2D' 

的build.gradle這樣

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:0.6.3' 
    } 
} 
apply plugin: 'android' 

dependencies { 
    compile project(':Modules:PhysicBox2D') 
    compile project(':Modules:AndEngine') 

} 

task wrapper(type: Wrapper) { 
    gradleVersion = '1.8' 
} 

android { 
    compileSdkVersion 19 
    buildToolsVersion "19" 

    sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
      java.srcDirs = ['MainProject/src'] 
      resources.srcDirs = ['MainProject/resources'] 
      aidl.srcDirs = ['MainProject/src'] 
      renderscript.srcDirs = ['MainProject/src'] 
      res.srcDirs = ['MainProject/res'] 
      assets.srcDirs = ['MainProject/assets'] 
     } 

     instrumentTest.setRoot('MainProject/tests') 
    } 

    dependencies { 

    } 

    defaultConfig { 
     ... 
    } 

    signingConfigs { 
     ... 
    } 

    buildTypes { 
     debug { 
      ... 
     } 
     release { 
      ... 
     } 
    } 
} 

模塊/ PhysicBox2D/settings.gradle

include ':Modules:AndEngineGLES2' 

模塊/ PhysicsBox2D /的build.gradle

buildscript { 
    repositories { 
     mavenCentral() 
    } 

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

apply plugin: 'android-library' 

    dependencies { 

     compile project(':Modules:AndEngineGLES2') 
     compile fileTree(dir: 'libs', include: 'libs.jar') 
    } 
    android { 

    buildToolsVersion "19" 
    compileSdkVersion 19 

    defaultConfig { 
     minSdkVersion 8 
     targetSdkVersion 19 
    } 

    repositories { 
     mavenCentral() 
    } 


sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
      java.srcDirs = ['src'] 
      resources.srcDirs = ['src'] 
      aidl.srcDirs = ['aidl'] 
      renderscript.srcDirs = ['src'] 
      res.srcDirs = ['res'] 
      assets.srcDirs = ['assets'] 
     } 
    } 
} 

模塊/ AndEngine /的build.gradle

buildscript { 
    repositories { 
     mavenCentral() 
    } 

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

apply plugin: 'android-library' 

dependencies { 
    compile fileTree(dir: 'libs', include: 'libs.jar') 
} 

android { 

    buildToolsVersion "19" 
    compileSdkVersion 19 

    defaultConfig { 
     minSdkVersion 8 
     targetSdkVersion 19 
    } 

    repositories { 
     mavenCentral() 
    } 


    sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
      java.srcDirs = ['src'] 
      resources.srcDirs = ['src'] 
      aidl.srcDirs = ['aidl'] 
      renderscript.srcDirs = ['src'] 
      res.srcDirs = ['res'] 
      assets.srcDirs = ['assets'] 
     } 
    } 
} 

,一切工作正常。我希望我已經提供了所有必要的信息使其運行。

+0

你從哪裏下載「AndEngine」和「PhysicBox2D」,我應該把它們放在哪裏? (谷歌指南在哪裏?) – user5262

+0

ANdEngine - https://github.com/nicolasgramlich/AndEngine/tree/GLES2-AnchorCenter,Box2D for AndEngine - https://github.com/nicolasgramlich/AndEngine/tree/GLES2- AnchorCenter – mar3kk

+0

感謝您的回覆。但是,你可以發佈一步一步的指示嗎? (即:1。創建目錄結構,2.提取.zip文件,3.?) – user5262