有没有办法让Android Instant App与本机C库一起使用?
我正在尝试将Android Instant App发布到设备/模拟器,但遇到了我的本机C库的问题.它作为可安装的应用程序发布,但在发布为Instant App时无法找到该库.
为了消除任何其他问题,我在Android Studio 3.0 (Canary 1 171.4010489)中使用新项目向导启动了一个新项目,并选择了以下设置:
第一页:
>包括C支持检查
第二页:
>选择手机和平板电脑
>已选中Android Instant App支持
第六页:
> C标准设置为’C 11′
>选中例外支持(-fexceptions)
>选中运行时类型信息支持(-frtti)
生成的项目将作为可安装的应用程序发布(显示’来自C’的屏幕’),但不是即时应用程序…它给出了以下错误,它无法找到库,这是我遇到的相同错误我的实际应用项目:
找不到“libnative-lib.so”
完整错误:
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"
...
我正在粘贴下面的相关gradle文件(全部由Android Studio生成):
应用程序/的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')
}
碱/的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'
}
功能/的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')
}
更新:
我向Google提出了一个问题:
虽然我觉得实现这一目标的工具已经可用(Gradle,CMake,NDK等)
还要感谢@Anirudh让我知道这是Android N上的一个已知问题.
发布没有C库的Instant App是否适用于我的设备?
是的…如果我创建一个仅包含Android Instant App支持的新Android Studio项目,它会发布到我的三星Galaxy 7S并显示“Hello World!”屏幕.
发布已签名的APK是否有效?
生成已签名的APK有效,经过检查,本机C库与feature-debug.apk捆绑在一起,但不与base-debug.apk捆绑在一起.这是我期望的gradle配置,但没有解释为什么它不会发布到设备/模拟器.
我还没有尝试过加载这些APK …但是我怀疑甚至可能因为从未安装过即时应用程序…例如:你如何在加载它之后启动它(点击一个网址?)
向两个APK添加C库是否有效?
我已经尝试将externalNativeBuild gradle属性添加到base / build.gradle和feature / build.gradle文件中,但仍然会出现相同的错误.我通过在生成签名APK后检查feature-debug.apk和base-debug.apk来验证原生C库是否包含在两个APK中.
修改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"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "../feature/CMakeLists.txt"
}
}
}
dependencies {
feature project(':feature')
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
Does publishing a signed APK work?
Android Studio 3.0预览生成签名APK功能目前有一个错误,其中最终的zip不包含所有功能apks.在每个要素模块的gradle文件中使用Gradle SigningConfig对要素apks进行签名
Does adding the C++ library to both APKs work?
不需要.添加基本功能apk应该足够了
实际崩溃是Android M / N上针对Android Instant Apps的NDK支持的已知问题.该应用程序适用于Android O模拟器
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。