如何向 build.gradle 添加调试符号

我已经创建了我的 Flutter 应用程序的 Android 版本。

然后我创建了一个内部测试版本,它显示了一个警告

这个应用程序包包含本机代码,您还没有上传调试 我们建议您上传一个符号文件,使您的崩溃 和 ANR 更容易分析和调试。

基本上,我要做的就是根据他们显示的链接将 follow 添加到 build.gradle 文件中。

android.buildTypes.release.ndk.debugSymbolLevel = { SYMBOL_TABLE | FULL }

我猜他们说的是 android/app/build.gradle。

不确定要在文件中的哪个位置添加这一行。

有人能指出在哪里加这一行吗?

53958 次浏览

There's two places in the app/build.gradle where you can specify bundling of debugging symbols with your app. If you use android.defaultConfig.ndk.debugSymbolLevel it will apply it to all build types (i.e., both debug and release builds). On the other hand, if you use android.buildTypes.release.ndk.debugSymbolLevel it will apply only to your release build.

These options have to be added into your app/build.gradle file as you correctly guessed. When you see a build property that's in this dotted notation, it actually corresponds to nested blocks in the build.gradle, which would look a bit like this:

android {
compileSdkVersion 28
defaultConfig {
applicationId 'com.example.foo'
minSdkVersion 23
targetSdkVersion 28
versionCode 42
versionName "4.0.2"
ndk {
debugSymbolLevel 'SYMBOL_TABLE'
}
}
// Rest of the file
}

HTH

To use the option ndk debugSymbolLevel as written in the docs you need an android gradle plugin 4.1 or later. At the time of writing the lastest 4.1 version is 4.1.2

You will need also to install ndk and cmake for android studio.

In your android build.gradle you need the to set android gradle plugin version 4.1.2:

buildscript {
...
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
...
}

Then in the android/app build.gradle add:

...
android {
...
// you see the ndk version in the android studio sdk-manager
// have a look also here: https://stackoverflow.com/a/65747847/9481613
ndkVersion "21.3.6528147"
...
buildTypes {
release {
...
ndk {
debugSymbolLevel 'SYMBOL_TABLE'
}
}
}
}

when you then run: flutter build appbundle it should finish after a while with an appbundle that is twice the size.

Use Android Version 4.1 and above currently 4.1 RC 3 and 4.2 Canary 13 is available, and similarly use com.android.tools.build:gradle 4.1 and above, you can search for the suitable version from here

Then use this line in android -> defaultConfig in your app build.gradle file

    ndk { debugSymbolLevel 'FULL' }

If none of solutions work, you can also create a Sample JNI Application from Android Studio's project templates. Build it and check whether it got built successfully and installed on a device.

I have inspected its app build.gradle file and compared my Flutter's build.gradle. So I added this to make it work:

defaultConfig {


// append below:
externalNativeBuild {
cmake {
cppFlags "-std=c++17"
}
}
}