26

this is my build gradle (app) file:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'checkstyle'

def versions = ['appcompat_v7' : '25.1.0',
                'butterknife'  : '8.4.0',
                'leak_canary'  : '1.5',
                'card_view'    : '25.1.0',
                'design'       : '25.1.0',
                'photoview'    : '1.2.4',
                'play_services': '10.0.1']



task checkstyle(type: Checkstyle) {
    configFile file("${project.rootDir}/checkstyle/checkstyle.xml")
    configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
    // Where is my suppressions file for checkstyle is...
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    classpath = files()
}


android {
    compileSdkVersion 25
    buildToolsVersion '27.0.3'
    flavorDimensions "versionCode"

    useLibrary 'org.apache.http.legacy'
    dexOptions {
        // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
        preDexLibraries = preDexEnabled && !travisBuild
    }

    defaultConfig {

        ndk {
            abiFilters 'x86', 'armeabi-v7a'
        }

        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }
    signingConfigs {
        release
    }
    buildTypes {
        debug {
            debuggable true
        }
        release {
            //runProguard true
            proguardFile file('android.pro')
            proguardFile getDefaultProguardFile('proguard-android.txt')
            signingConfig signingConfigs.release
        }
    }

    splits {
        abi {
            enable true
            reset()
            include 'x86', 'armeabi-v7a'
            universalApk true
        }
    }

    // map for the version code


    productFlavors {

        playstore {

        }
        develop {
        }
    }


    lintOptions {
        //I'm too lazy to translate everything
        abortOnError false
    }
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }
}

def Properties props = new Properties()
def propFile = new File('signing.properties')
if (propFile.canRead()) {
    props.load(new FileInputStream(propFile))

    if (props != null && props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&
            props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {
        android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
        android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
    } else {
        println 'signing.properties found but some entries are missing'
        android.buildTypes.release.signingConfig = null
    }
} else {
    println 'signing.properties not found'
    android.buildTypes.release.signingConfig = null
}

buildscript {
    repositories {
        jcenter()
        mavenCentral()

    }
}


dependencies {
    compile project(":tess-two:tess-two")
    compile project(":volley")
    compile project(":real-time-ocr")

    compile 'com.github.barteksc:pdfium-android:1.5.0'
    compile fileTree(dir: 'src/main/libs', include: '*.jar')

    debugCompile "com.squareup.leakcanary:leakcanary-android:${versions.leak_canary}"
    releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:${versions.leak_canary}"
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile "com.commit451:PhotoView:${versions.photoview}"
    compile 'com.google.code.findbugs:jsr305:2.0.2'
    compile "com.google.guava:guava:18.0"
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'com.nineoldandroids:library:2.4.0'
    compile "com.android.support:design:${versions.design}"
    compile "com.android.support:appcompat-v7:${versions.appcompat_v7}"
    compile 'org.apache.commons:commons-compress:1.5'
    compile "com.android.support:cardview-v7:${versions.card_view}"
    compile 'com.google.code.gson:gson:2.8.2'
    compile "com.jakewharton:butterknife:${versions.butterknife}"
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    compile 'com.google.android.gms:play-services-vision:9.4.0+'
    compile group: 'com.facebook.android', name: 'facebook-android-sdk', version: '4.25.0'



    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
    androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
    androidTestCompile 'org.mockito:mockito-core:1.10.17'
    androidTestCompile 'junit:junit:4.12'


    testCompile 'junit:junit:4.12'
    testCompile "org.mockito:mockito-all:1.10.19"
    testCompile("org.robolectric:robolectric:3.0-rc2") {
        exclude group: 'commons-logging', module: 'commons-logging'
    }
    compile('com.crashlytics.sdk.android:crashlytics:2+') {
        transitive = true;
    }
    compile('com.crashlytics.sdk.android:crashlytics-ndk:1+@aar') {
        transitive = true;
    }


    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.shawnlin:number-picker:2.4.4'
    compile 'com.squareup.picasso:picasso:2.5.2'



}
crashlytics {
    enableNdk true
    androidNdkOut '/Users/renard/devel/textfairy/tess-two/tess-two/obj'
    androidNdkLibsOut '/Users/renard/devel/textfairy/tess-two/tess-two/libs'
}
apply plugin: 'com.google.gms.google-services'

android studio can't sync project and get me this error:

Conflicting configuration : 'armeabi-v7a,x86' in ndk abiFilters cannot be present when splits abi filters are set : x86,armeabi-v7a

Configuration 'compile' is obsolete and has been replaced with 'implementation'. It will be removed at the end of 2018

Configuration 'debugCompile' is obsolete and has been replaced with 'debugImplementation'. It will be removed at the end of 2018

Configuration 'androidTestApi' is obsolete and has been replaced with 'androidTestImplementation'. It will be removed at the end of 2018

Configuration 'releaseCompile' is obsolete and has been replaced with 'releaseImplementation'. It will be removed at the end of 2018

Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation'. It will be removed at the end of 2018

Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'. It will be removed at the end of 2018

Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestImplementation'. It will be removed at the end of 2018

The option 'android.enableAapt2' is deprecated and should not be used anymore. Use 'android.enableAapt2=true' to remove this warning. It will be removed at the end of 2018.

Configuration 'compile' is obsolete and has been replaced with 'implementation'. It will be removed at the end of 2018

The option 'android.enableAapt2' is deprecated and should not be used anymore. Use 'android.enableAapt2=true' to remove this warning. It will be removed at the end of 2018.

Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation'. It will be removed at the end of 2018

Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'. It will be removed at the end of 2018

The option 'android.enableAapt2' is deprecated and should not be used anymore. Use 'android.enableAapt2=true' to remove this warning. It will be removed at the end of 2018.

Configuration 'compile' is obsolete and has been replaced with 'implementation'. It will be removed at the end of 2018

if I delete this line

defaultConfig {

    ndk {
        abiFilters 'x86', 'armeabi-v7a'
    }

the project sync sucessfully but when build give me this error

Failed to execute aapt

I already try to clean and rebuild project but still not working! I also post the build.gradle (Project) file

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1+'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath 'com.android.tools.build:gradle:3.1.0'
    }
}



allprojects {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        maven { url "http://dl.bintray.com/populov/maven" }
        jcenter()
        maven {
            url "http://oss.sonatype.org/content/repositories/snapshots"
        }
        maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local/' }
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }

}

ext {
    travisBuild = System.getenv("TRAVIS") == "true"
    // allows for -Dpre-dex=false to be set
    preDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))
}

my gradle-wrapper.properties file

    #Tue Mar 27 14:42:14 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

and my gradle.properties file

    ndkDir=/Users/giuliopettenuzzo/Library/Android/sdk/ndk-bundle
org.gradle.jvmargs=-XX\:MaxPermSize\=512m
android.enableAapt2=false

5 Answers 5

34

ndk.abiFilters configuration means that only selected processor architectures of native libraries will be included in the final APK.

On the other hand, splits.abi.enable true tells the compiler to generate separated APKs for selected architectures.

It seams that this two configuration can't be set together. So you have two options:

  1. Disable splitting APK (you've figured it out already). Than you will have one APK.

  2. Remove ndk.abiFilters setting. Than you will have multiple (probably much smaller) APKs. Moreover, with universalApk true, an universal APK with all architectures will be generated (probably much larger than in option 1).

Than, replace compile with new keyword implementation. I think, this is clear from error message.

1
  • 1
    > Moreover, with universalApk true, an universal APK with all architectures will be generated (probably much larger than in option 1). This is insanely stupid. If I want abi split, I get invalid universal apk if, for instance, my dependencies provide more abis they I do. Commented Sep 21, 2018 at 12:45
7

Finally I got it working by putting

abi {
    enable false
    reset()
    include 'x86', 'armeabi-v7a'
    universalApk true
}

and multiDexEnabled true but I don't know if this sorted out the problem or just ignoring the error.

4
  • 3
    Where should i put this ? in Default config? Commented Apr 13, 2018 at 5:40
  • @HarshBhavsar You should put this in android/app/build.gradle Commented Jun 14, 2018 at 16:17
  • @PratikSinghal Where? I put in that file and i have error "Coiuld not find method abi() for arguments[build_randomchars_run_closure3@randomnumbers] on root project ':app' of type org.gradle.api.Project.
    – manudicri
    Commented Jun 23, 2018 at 16:30
  • @DiCri There are two build.gradle files. Are you sure, you are trying to put it in right file ? You need to put it in android/app/build.gradle and not android/build.gradle. Commented Jun 24, 2018 at 16:16
2

I had to add "x86" here:

ndk {
    abiFilters "armeabi-v7a", "arm64-v8a", "x86"
}

inside the defaultConfig.

0

I opened an old project and when I wanted to build it, I was getting a lot of error which was very frustrating. I replaced compile with implementation and added all the required codes. At last the project built successfully.

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation ('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.facebook.android:facebook-android-sdk:4.+'
    implementation 'com.facebook.android:account-kit-sdk:4.+'
    implementation 'com.android.volley:volley:1.1.0-rc2'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'
    testImplementation 'junit:junit:4.12'
}
0
dependencies {
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.google.android.gms:play-services-maps:9.6.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation ('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation 'com.google.firebase:firebase-core:9.6.1' //referencia  a la version de firebase
implementation 'com.google.firebase:firebase-database:9.6.1' // referencia a la base de datos
implementation 'com.google.firebase:firebase-auth:9.6.1'
implementation 'com.google.android.gms:play-services-auth:9.6.1'

implementation 'com.google.android.gms:play-services-maps:9.6.1'

// aqui se agrega la referencia a la autentificacion
}

**replace compile by implemenntation androidCompileTest by androidTestImplementation **

1
  • I don't know why this answer get downvoted, but this works for me, and somehow reasonable according to what Android Studio informed after my previous gradle build.
    – adadion
    Commented Jun 25, 2018 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.