在发布模式下崩溃,但如果可调试为 true - 不是..什么是可能的问题



我用ndk + openGL做了一个示例项目。该应用程序的想法很简单,当您点击屏幕时打开相机,AR对象出现在您点击的位置。

当我在debug mode工作时,一切都很好,但是在我切换release mode后,编译还可以,我可以打开相机,但是当我点击屏幕时,应用程序崩溃了。

当然有日志...因此,要打开日志选项(为了找出崩溃的原因(,我在release部分中添加了这样的行debuggable true

但是,现在当我点击屏幕时,应用程序不会崩溃......

崩溃的可能原因是什么?如果我只用debuggable false崩溃并且看不到日志,我该如何检查它......?

这是我的gradle

apply plugin: 'com.android.application'
/*
The arcore aar library contains the native shared libraries.  These are
extracted before building to a temporary directory.
*/
def arcore_libpath = "${buildDir}/arcore-native"
// Create a configuration to mark which aars to extract .so files from
configurations { natives }
android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.google.ar.core.examples.c.helloar"
    // 24 is the minimum since ARCore only works with 24 and higher.
    minSdkVersion 24
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    signingConfig signingConfigs.debug
    externalNativeBuild {
        cmake {
            cppFlags "-std=c++11", "-Wall"
            arguments "-DANDROID_STL=c++_static",
                    "-DARCORE_LIBPATH=${arcore_libpath}/jni",
                    "- 
 DARCORE_INCLUDE=${project.rootDir}
/../../libraries/include"
        }
    }
    ndk {
        abiFilters "arm64-v8a", "armeabi-v7a", "x86"
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
    release {
        debuggable true
        minifyEnabled false
        proguardFiles getDefaultProguardFile
('proguard-android.txt'), 'proguard-rules.pro'
    }
}
externalNativeBuild {
    cmake {
        path "CMakeLists.txt"
    }
}
}
dependencies {
// ARCore library
implementation 'com.google.ar:core:1.9.0'
natives 'com.google.ar:core:1.9.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
}
// Extracts the shared libraries from aars in the natives configuration.
// This is done so that NDK builds can access these libraries.
task extractNativeLibraries() {
// Always extract, this insures the native libs 
are updated if the version changes.
outputs.upToDateWhen { false }
doFirst {
    configurations.natives.files.each { f ->
        copy {
            from zipTree(f)
            into arcore_libpath
            include "jni/**/*"
        }
    }
}
}
tasks.whenTaskAdded {
task-> if (task.name.contains("external") && !task.name.contains("Clean")) {
    task.dependsOn(extractNativeLibraries)
}
}

和应用格拉德尔

// Top-level build file where you can add 
configuration options common to all sub-projects/modules.
buildscript {
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}
allprojects {
repositories {
    google()
    jcenter()
    mavenLocal()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

编辑

在这里我得到了一些日志输出

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/crownltexx/crownlte:9/PPR1.180610.011/N960FXXU2CSDE:user/release-keys'
Revision: '28'
ABI: 'arm64'
pid: 11411, tid: 11600, name: GLThread 82400    >>> com.myapp.ar <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: 'terminating with uncaught exception of type std::bad_alloc: std::bad_alloc'
        x0    0000000000000000    x1    0000000000002d50    x2    0000000000000006    x3    0000000000000008
        x4    fefefefefefefeff    x5    fefefefefefefeff    x6    fefefefefefefeff    x7    7f7f7f7f7f7f7f7f
        x8    0000000000000083    x9    0000007f5c9fa890    x10 fffffff87ffffbdf    x11 0000000000000001
        x12 0000000000000018    x13 000000005d0788d4    x14 00057c28f4018340    x15 00001ef146270368
        x16 0000007f5ca312b0    x17 0000007f5c970958    x18 0000000000000000    x19 0000000000002c93
        x20 0000000000002d50    x21 0000000000000083    x22 ffffff80ffffffc8    x23 0000007e94b00cb0
        x24 0000007e94b00b90    x25 0000007e94b00bd0    x26 0000000000000016    x27 ffffffffffffffb0
        x28 0000007ebfc24e9c    x29 0000007e94b00b00
        sp    0000007e94b00ac0    lr    0000007f5c963da0    pc    0000007f5c963dcc
backtrace:
        #00 pc 0000000000021dcc    /system/lib64/libc.so (abort+124)
        #01 pc 00000000000cccac    /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so
        #02 pc 00000000000cce0c    /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so
        #03 pc 00000000000c9bf0    /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so
        #04 pc 00000000000c92f8    /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so
        #05 pc 00000000000c9278    /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (__cxa_throw+120)
        #06 pc 00000000000cc588    /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (operator new(unsigned long)+84)
        #07 pc 000000000006c3c0    /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::append(char const*, unsigned long)+264)
        #08 pc 000000000006e59c    /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (FrameManager::LoadImage(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>)+280)
        #09 pc 0000000000050ed8    /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (hello_ar::VideoRender::thread_task2(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>, std::__ndk1::shared_ptr<FrameManager>)+60)
        #10 pc 000000000006c800    /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (_ZNSt6__ndk114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN8hello_ar11VideoRenderEFvNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEENS_10shared_ptrI12FrameManagerEEEPS8_SE_SH_EEEEEPvSM_+132)
        #11 pc 0000000000084df8    /system/lib64/libc.so (__pthread_start(void*)+208)
        #12 pc 0000000000023ac4    /system/lib64/libc.so (__start_thread+68)

编辑

LoadImage方法

void FrameManager::LoadImage(std::string const & path)
{
std::ifstream file(path, std::ios::binary);
const int PKM_HEADER_SIZE = 16;
char pkmHeader[PKM_HEADER_SIZE];
file.read(pkmHeader, sizeof(pkmHeader));
std::string magicNumber = "";
magicNumber.append("" + ((char) pkmHeader[0]));
magicNumber.append("" + ((char) pkmHeader[1]));
magicNumber.append("" + ((char) pkmHeader[2]));
magicNumber.append("" + ((char) pkmHeader[3]));
m_image_width = ((int) pkmHeader[9]) | (((int) pkmHeader[8]) << 8);
m_image_height = ((int) pkmHeader[11]) | (((int) pkmHeader[10]) << 8);
const int BLOCK_DIM = 4;
const int BLOCK_PIXELS = BLOCK_DIM * BLOCK_DIM;
const int BLOCK_BITS = 64;
int size = (BLOCK_BITS / 8) * m_image_width * m_image_height /
 (BLOCK_PIXELS);
m_imageData.resize(size);
int pos = 0;
while (size > 0)
{
    file.read((char *) &m_imageData[pos], size);
    pos += (int) file.gcount();
    size -= (int) file.gcount();
}
file.close();
}

"" + ((char) pkmHeader[0])是一个const char*,因此std::string::append((可以接收它。但是这个const char*的值不是"A"(假设pkmHeader[0] == 'A'(。"" + ((char) pkmHeader[0]) 的结果是一个指向(预分配(""常量的指针,该指针的偏移量为 65。给我的

printf("%p %pn", "", "" + ((char) 'A') );

指纹:

0x7f3cbf201025 0x7f3cbf201066

注意0x7f3cbf201066 - 0x7f3cbf201025 = 0x41,"A"的值。

若要修复代码,请使用

magicNumber.append(pkmHeader, 4);

相关内容

最新更新