標籤:
使用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‘)
}
提示下面的錯誤,是主工程和引用工程合并AndroidManifest時,衝突,
AndroidManifest.xml:33:9-41 Error:
Attribute [email protected] value=(@string/ime_name) from AndroidManifest.xml:33:9-41
is also present at [App2:unspecified] AndroidManifest.xml:38:9-51 value=(@string/appcenter_app_name)
解決辦法:
在主工程的AndroidManifest.xml檔案的<application>內添加下面的內容tools:replace="android:label,android:name"
哪些衝突添加哪些
然後在<manifest>內添加xmlns:tools="http://schemas.android.com/tools"
最新版Android Studio NDK調試:跟目錄下local.properties檔案指定ndk和sdk目錄ndk.dir=/home/***/work/sdk/ndk-bundlesdk.dir=/home/***/work/sdksettings.gradle檔案指定匯入的工程include ‘:mainApp‘include ‘:libApp‘gradle/wrapper/gradle-wrapper.properties檔案distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdistributionUrl=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(: , : [])}
Android Studio使用筆記