Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

androidNdkOut and androidNdkLibsOut auto detection for library not working

Newest Fabric documentation says

If using the Android plugin for Gradle version 2.2.0+ with the externalNativeBuild DSL, you should remove the androidNdkOut and androidNdkLibsOut properties, as these paths will automatically be detected by the Fabric plugin. But it's not working for me because my native code located in library module I guess. I have native code in library module and enabled Crashlytics in app module. How can I make it work?

I am using com.android.tools.build:gradle:2.3.3 and io.fabric.tools:gradle:1.23.0.

Error:

com.crashlytics.tools.android.project.codemapping.CodeMappingException: Crashlytics could not find NDK output directory '[my app module path]/obj'. Is the -androidNdkOut setting configured correctly?

UPDATE. I moved Crashlytics configuration to my library module:

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath('com.android.tools.build:gradle:2.3.3') {
            force = true
        }
        classpath 'io.fabric.tools:gradle:1.23.0'
    }
}

repositories {
    jcenter()
}

apply plugin: 'com.android.library'
apply plugin: 'io.fabric'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    publishNonDefault true

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"

        ndk {
            moduleName "core"
        }

        externalNativeBuild {
            ndkBuild {
                abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mips64"
            }
        }
    }

    lintOptions {
        abortOnError false
    }

    buildTypes {
        debug {
            debuggable true
            jniDebuggable true
            minifyEnabled false
        }
        release {
            debuggable false
            jniDebuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    externalNativeBuild {
        ndkBuild {
            path 'jni/Android.mk'
        }
    }
}

crashlytics {
    enableNdk true
    baseManifestPath '../app/src/main/AndroidManifest.xml'
}

dependencies {
    compile "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
    compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    compile "com.android.support:design:${rootProject.ext.supportLibVersion}"
    compile "com.google.android.gms:play-services-maps:${rootProject.ext.playServicesVersion}"
    compile "com.google.android.gms:play-services-location:${rootProject.ext.playServicesVersion}"
}

My app module now contains only dependencies:

dependencies {    
    // Crashlytics Kit
    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true
    }
    // NDK Kit
    compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6@aar') {
        transitive = true
    }
}

But now I getting error

Could not find method baseManifestPath() for arguments [path to my Manifest] on object of type com.crashlytics.tools.gradle.CrashlyticsExtension.

like image 587
rzhik Avatar asked Dec 23 '22 16:12

rzhik


2 Answers

I faced with same issue. I have main application module 'app' and 'library' module contains ndk sources.

Update June 2019

Last month I've been gotten an error while performing 'crashlyticsUploadSymbolsRelease' command with gradle. Seems location of libs files changed.

The following code allows me to see NDK crashes with line numbers:

crashlytics {
    enableNdk true
    androidNdkOut '../library/build/intermediates/cmake/release/obj'
    androidNdkLibsOut '../library/build/intermediates/stripped_native_libs/release/out/lib'
}

Hope it helps.

like image 183
kasurd Avatar answered May 08 '23 13:05

kasurd


Mike from Fabric here. That improvement will help when the NDK assets are built directly into your app, but not when building as a separate library project. When the native code is part of an external library, the project structure may differ. You’ll need to include an Ant or Gradle task to temporarily create the appropriate project structure before running the symbol upload.

Once you have assembled the appropriate project structure and you have your AndroidManifest.xml file available, you’ll need to set a few properties for the Fabric plugin to use.

Using Ant

For Ant, you should create a fabric.properties file with the following properties:

enableNDK=true
androidBaseManifest=AndroidManifest.xml
externalCSymUpload=true

Then, to run the symbol upload, invoke the crashlytics-devtools.jar which can be found inside the Ant plugin zip file. Calling java -jar crashlytics-devtools.jar -properties fabric.properties will start the upload process.

The androidBaseManifest property defines the path to the AndroidManifest.xml file with your app’s API key and package name.

Using Gradle For Gradle, you’ll need a minimal Android build.gradle file and you can define the properties directly in a crashlytics {} block: The Fabric Gradle plugin requires the Android Gradle plugin to be applied before it in your build.gradle.

apply plugin: 'com.android.library'
apply plugin: 'io.fabric'

android {
  compileSdkVersion <CURRENT COMPILESDKVERSION>
  buildToolsVersion "<YOUR BUILD TOOLS VERSION>"

  defaultConfig {
    applicationId "<YOUR APP'S PACKAGE NAME>"
  }
}

crashlytics {
  enableNdk true
  baseManifestPath 'AndroidManifest.xml'
}

Then run ./gradlew crashlyticsUploadSymbolsRelease to upload your symbols.

like image 36
Mike Bonnell Avatar answered May 08 '23 15:05

Mike Bonnell