mercredi 24 mai 2017

Android Instant App not publishing with Native C++ Library

Is there a way to get an Android Instant App working with a native C++ library?

I'm attempting to publish an Android Instant App, but ran into problems with my native C++ library. It publishes fine as an installable app, but fails to find the library when published as an Instant App.

To eliminate any other issues, I started a new project in Android Studio (Version 3.0 Canary 1 (171.4010489) with the new project wizard and selected the following settings:

First Page:

  • Include C++ support checked

Second Page:

  • Phone and Tablet selected
  • Include Android Instant App support checked

Sixth Page:

  • C++ Standard set to 'C++11'
  • Exceptions Support (-fexceptions) checked
  • Runtime Type Information Support (-frtti) checked

The resulting project will publish as an installable app (showing the 'Hello from C++' screen), but not an instant app... it gives the following error that it can't find the library, which is the same error I get in my actual app's project:

couldn't find "libnative-lib.so"

Full error:

05-24 17:48:30.316 7519-7519/? E/AndroidRuntime: FATAL EXCEPTION: main
     Process: com.mycompany.instantapp, PID: 7519
     java.lang.UnsatisfiedLinkError: byc[DexPathList[[zip file "/data/user/0/com.google.android.instantapps.supervisor/files/atom-cache/com.mycompany.instantapp/atom-download--feature-1495662507463/feature.jar"],nativeLibraryDirectories=[/data/user/0/com.google.android.instantapps.supervisor/files/native-lib/com.mycompany.instantapp, /system/lib, /vendor/lib]]] couldn't find "libnative-lib.so"
     ...

I'm pasting the relevant gradle files below (all generated by Android Studio):

app/build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0 rc2"


    defaultConfig {
        applicationId "com.mycompany.instantapp"
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"


    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation project(':feature')
    implementation project(':base')
}

base/build.gradle:

apply plugin: 'com.android.feature'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0 rc2"
    baseFeature true
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    feature project(':feature')
    compile 'com.android.support:appcompat-v7:25.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}

feature/build.gradle:

apply plugin: 'com.android.feature'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0 rc2"
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -frtti -fexceptions"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation project(':base')
    testCompile 'junit:junit:4.12'

}

instantapp/build.gradle:

apply plugin: 'com.android.instantapp'

dependencies {
    implementation project(':feature')
    implementation project(':base')
}

Aucun commentaire:

Enregistrer un commentaire