【问题标题】:App crashes when shared and works fine when tested using debug mode共享时应用程序崩溃,并且在使用调试模式测试时工作正常
【发布时间】:2017-01-18 19:33:12
【问题描述】:

我已经在多台设备上测试了我的应用程序

果冻豆、奇巧、棒棒糖、棉花糖

直接从我的应用程序中使用调试,并从一部手机共享到另一部手机。

它在所有手机中都可以正常工作(不包括一个)

我有一部 kitkat(4.4.4) Moto G 手机,其中的应用程序在其他设备上运行良好,但是当我共享此应用程序并运行时,应用程序崩溃 在它打开之前。

不知道该怎么做,因为我不知道可能是什么错误,因为使用 usb 调试 运行正常。

我的 Gradle 构建

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.1"

    defaultConfig {
        applicationId "com.abc.xyz"
        minSdkVersion 16
        targetSdkVersion 24

    }
    buildTypes {

        debug {
            minifyEnabled true
        }
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }

}

【问题讨论】:

  • 发布错误日志...
  • @Divyesh Hi Divyesh 但错误日志来自哪里?
  • @Divyesh 应用程序在 USB 调试下运行良好,但在共享时崩溃,所以我想我不知道错误会在哪里产生,因为我不知道移动设备中的 apk 错误日志...... .并且在第一个活动的 onCreate 中,我想我没有调用任何 api,如果我在制作 api 的不同网络上也会产生错误
  • 在应用中添加分析服务。像织物
  • 你是怎么分享的?使用另一个应用程序??尝试发送电子邮件,看看是否仍然出现集成崩溃报告工具stackoverflow.com/documentation/android/drafts/106510

标签: android


【解决方案1】:

我也遇到过这个问题,我能找到的唯一可行的解​​决方案是从 android studio 的设置中禁用 instant run。然后进行干净的构建并生成一个新的app-debug.apk。与多个设备共享此 apk

【讨论】:

  • 是的,这就是我希望在我最近升级我的工作室后即时运行显示出来的东西......但仍然需要实施崩溃报告......
  • 安装apk,然后将kitkat手机插上pc就可以得到logcat崩溃报告
  • 它工作得很好,你知道我也必须从我的 gradle 中删除那个 debug{minifyEnable true} 因为有一些错误,当我使用即时运行时,这个调试没有引起任何问题.. ...不知道发生了什么
  • 不确定,我从未在调试版本中使用过minifyEnable true
  • 但我必须知道是什么导致了崩溃,因为启用了即时运行......好吧,如果我知道一些关于它的信息,我会在这里评论这个问题
【解决方案2】:

这不是您的问题的直接解决方案,但它会帮助您找到任何应​​用程序崩溃的解决方案。

添加 CustomExceptionHandler 类,该类将为应用程序中的任何崩溃写入日志

public class CustomExceptionHandler implements UncaughtExceptionHandler {

private UncaughtExceptionHandler defaultUEH;

private String localPath;

private String url;

/* 
 * if any of the parameters is null, the respective functionality 
 * will not be used 
 */
public CustomExceptionHandler(String localPath) {
    this.localPath = localPath;
    this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
}

public void uncaughtException(Thread t, Throwable e) {
    String timestamp = TimestampFormatter.getInstance().getTimestamp();
    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    e.printStackTrace(printWriter);
    String stacktrace = result.toString();
    printWriter.close();
    String filename = timestamp + ".stacktrace";

    if (localPath != null) {
        writeToFile(stacktrace, filename);
    }


    defaultUEH.uncaughtException(t, e);
}

private void writeToFile(String stacktrace, String filename) {
    try {
        BufferedWriter bos = new BufferedWriter(new FileWriter(
                localPath + "/" + filename));
        bos.write(stacktrace);
        bos.flush();
        bos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

并在mainActivity中添加这段代码

if(!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(
        "/sdcard/<desired_local_path>"));
}

希望这对您有所帮助...!

【讨论】:

  • 我在哪里可以看到这个应用程序日志 --> sdcard/", "http:///upload.php"
  • 这会做什么请详细说明 Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler( "/sdcard/", "http:///upload.php"));
  • 意思是,日志文件生成并发送到php文件服务器
  • 请确保在粘贴其他来源的代码时对其进行修改以回答特定问题。以上代码需要修改为仅写入本地文件而不向任何服务器发送数据。
  • @akash93 是的,但是如果删除这个“http:///upload.php”,那么它是否只写入文件我的意思是第二个参数我不需要写?
猜你喜欢
  • 2019-12-05
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
  • 1970-01-01
  • 2015-03-27
  • 1970-01-01
  • 2015-04-04
  • 2020-12-21
相关资源
最近更新 更多