我在 Android Studio 中有一个项目,其中包含通过 JNI 调用使用一些本机库的 Android Java 服务。
基本上,我有两个编译的库和另一个预编译的库,所以我无法访问源代码。由于预编译库仅为armeabi-v7a 构建,因此我有一个abiFilter。
在这里,我的/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'io.fabric.tools:gradle:1.31.2'
classpath 'com.google.gms:google-services:4.3.3' // Google Services plugin
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
和我的 /app/build.gradle (省略了合理的代码)
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
def enableCrashlyticsNdk = true
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
android {
signingConfigs {
platformSignature {
keyAlias "${platform_keystore_alias}"
keyPassword "${platform_keystore_password}"
storeFile file("${platform_keystore_path}")
storePassword "${platform_keystore_password}"
}
}
compileSdkVersion 29
buildToolsVersion "29.0.2"
lintOptions {
abortOnError false
}
defaultConfig {
applicationId com.example.stackoverflowapp
minSdkVersion 26
targetSdkVersion 28
versionCode 1
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -Werror"
}
}
ndk {
// Specifies the ABI configurations of your native
// libraries Gradle should build and package with your APK.
abiFilters 'armeabi-v7a'
}
}
buildTypes {
release {
minifyEnabled true
jniDebuggable false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.platformSignature
}
debug {
debuggable true
jniDebuggable true
versionNameSuffix = " (debug)"
signingConfig signingConfigs.platformSignature
}
}
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = buildOutputName(variant)
}
}
packagingOptions {
exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
exclude 'error_prone/Annotations.gwt.xml'
exclude 'third_party/java_src/error_prone/project/annotations/Annotations.gwt.xml'
exclude 'third_party/java_src/error_prone/project/annotations/Google_internal.gwt.xml'
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
ext {
appCompatVersion = '28.0.0'
}
crashlytics {
enableNdk enableCrashlyticsNdk
}
tasks.whenTaskAdded { task ->
if (enableCrashlyticsNdk && task.name.startsWith('assemble')) {
task.finalizedBy "crashlyticsUploadSymbols" + task.name.substring('assemble'.length())
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.leanback:leanback:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.exoplayer:exoplayer:r1.5.14'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.crashlytics.sdk.android:crashlytics-ndk:2.1.1'
}
apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
由于我的应用程序是 Android 系统的一部分,因此它是使用平台签名进行签名的。
我用 CMake 编译了 2 个库。
我已遵循 firebase web 中的所有步骤:
- https://firebase.google.com/docs/android/setup
- https://firebase.google.com/docs/crashlytics/get-started?platform=android
- https://firebase.google.com/docs/crashlytics/ndk-reports
我故意在我的一个库中添加了崩溃,当应用程序崩溃时,Crashlytics 会收集崩溃并成功上传崩溃报告。
CrashlyticsCore: Crashlytics report upload complete: 5DE66A450116-0001-1A8B-A3EE77BA9366
然后,当我进入 firebase 控制台时,我看到所有堆栈帧都(丢失)
Crashed: Thread #1
SIGSEGV 0x0000000000000028
-------------------------------------------
0 MyApp.apk (Missing)
1 libart.so (Missing)
2 (Missing)
3 (Missing)
4 (Missing)
5 (Missing)
6 (Missing)
7 libart.so (Missing)
8 libart.so (Missing)
9 libart.so (Missing)
10 (Missing)
11 libart.so (Missing)
12 (Missing)
查看 Crashlytics 构建日志,cSym 文件似乎已正确上传。
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics - cSYM file(s) uploaded.
我不太确定符号是否正确创建和上传,或者设备创建的崩溃报告是否存在问题。我担心这个问题与 android 权限有关,因为我的应用程序是系统应用程序。
我想我已经阅读了所有与 Crashlytics 和 NDK 相关的 stackoverflow 帖子。另外,我还用谷歌搜索了与“crashlytics、ndk 和符号”相关的任何类型的组合。
最后,我使用的工具版本:
- 安卓工作室:3.5.1
- 摇篮:5.4.1
- Gradle 插件:3.5.2
- Fabric gradle 插件:1.31.2
太感谢了。