使用Gradle方式:
如果编译成功,运行提示
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/home/zhaokun/work/jdk1.7.0_71/bin/java‘‘ finished with non-zero exit value 2
可以在工程根目录下运行./gradlew installDebug --stacktrace,或者在IDE窗口Gradle console 发现有下面的提示
com.android.dex.DexIndexOverflowException: Cannot merge new index 65949 into a non-jumbo instruction!
在主工程的build.gradle文件,android{} 内添加如下内容
android.dexOptions { jumboMode = true // javaMaxHeapSize "2g" } Eclipse 中是在project.properties中添加dex.force.jumbo=true 导入第三方库的源代码时,把源代码copy到工程根目录,源代码目录下新建build.gradle文件(内容根据各自工程而定):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:1.3.0‘
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: ‘android-library‘
android {
compileSdkVersion 19
buildToolsVersion "23.0.0 rc3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 11
}
sourceSets {
main {
manifest.srcFile ‘AndroidManifest.xml‘
java.srcDirs = [‘src‘]
resources.srcDirs = [‘src‘]
aidl.srcDirs = [‘src‘]
renderscript.srcDirs = [‘src‘]
res.srcDirs = [‘res‘]
assets.srcDirs = [‘assets‘] jniLibs.srcDirs = [‘libs‘]
}
}
}
dependencies {
compile files(‘libs/××××.jar‘)
}
最新版Android Studio NDK调试: 跟目录下 local.properties文件指定ndk和sdk目录 ndk.dir=/home/***/work/sdk/ndk-bundle sdk.dir=/home/***/work/sdk settings.gradle文件指定导入的工程 include ‘:mainApp‘ include ‘:libApp‘ gradle/wrapper/gradle-wrapper.properties文件 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip 根目录下build.gradle文件: buildscript { repositories { jcenter() } dependencies { classpath ‘com.android.tools.build:gradle-experimental:0.2.0‘ } } allprojects { repositories { jcenter() } } Module工程目录下build.gradle:
apply plugin: ‘com.android.model.application‘ model { android { compileSdkVersion = buildToolsVersion = defaultConfig.with { applicationId = minSdkVersion.apiLevel = targetSdkVersion.apiLevel = } } android.buildTypes { release { minifyEnabled = proguardFiles += file() } } android.ndk { moduleName = String srcDirs = ${projectDir}String includeSrcBase = ${srcDirs}String includeSrc2Base = ${srcDirs}stl += CFlags += [ includeSrcBase, includeSrc2Base] cppFlags += [ includeSrcBase, includeSrc2Base] } android.productFlavors { create() { ndk.abiFilters += } create() { ndk.abiFilters += } create() { ndk.abiFilters += } create() { ndk.abiFilters += } create() { ndk.abiFilters += } create() { ndk.abiFilters += } create() { ndk.abiFilters += } create() } android.dexOptions { jumboMode = } android.buildTypes { release { minifyEnabled = proguardFiles += file() } } android.sources { { manifest.source.srcDirs = []java.source.srcDirs = [] resources.source.srcDirs = [] aidl.source.srcDirs = [] renderscript.source.srcDirs = [] res.source.srcDirs = [] assets.source.srcDirs = [] jniLibs.source.srcDirs = [] jni.source.srcDirs = [] } } } dependencies { compile project() compile fileTree(: , : []) }
原文:http://my.oschina.net/mutour/blog/492324