ACRA无法正常工作,但我正确设置了它

时间:2017-07-26 14:52:06

标签: java android acra

我在Android Studio使用Android上的ACRA作为我的应用程序,我相当确定所有内容都已正确设置:

package prospect.firmname.net.prospect;
import android.app.Application;
import android.content.Context;

import org.acra.*;
import org.acra.annotation.*;
import org.acra.sender.HttpSender;

import static org.acra.ACRA.log;

@ReportsCrashes(
    formUri = "http://prospect.firmname.net/report.php",
    reportType = HttpSender.Type.JSON,
    httpMethod = HttpSender.Method.POST,
    customReportContent = {
            ReportField.APP_VERSION_CODE,
            ReportField.APP_VERSION_NAME,
            ReportField.ANDROID_VERSION,
            ReportField.PACKAGE_NAME,
            ReportField.REPORT_ID,
            ReportField.BUILD,
            ReportField.STACK_TRACE
    },
    mode = ReportingInteractionMode.TOAST
)
public class ProspectApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        log.e("ACRA BOOTING","OK");
        ACRA.init(this);
    }
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        ACRA.init(this);
    }
  }

我添加了log.e("ACRA BOOTING","OK");,它出现在调试中,我将两个 @overrides排除在绝望之外,但最初它是this page here:< / p>

主要节日看起来像这样

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:name="ProspectApplication"
        android:theme="@style/AppTheme">            
           ~~~~
    </application>

gradle文件看起来像这样

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "prospect.firmname.net.prospect"
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.googlecode.json-simple:json-simple:1.1'
    compile 'ch.acra:acra:4.9.2'
    testCompile 'junit:junit:4.12'
}

android {
    useLibrary 'org.apache.http.legacy'
}

当我手动访问网址http://prospect.firmname.net/report.php(触摸网站)时,它会记录访问,完全是因为我使用此代码(我添加了一个error_log以100%确定它的工作原理),它记录访问时我手动执行它如果应用程序崩溃,它永远不会记录访问:

report.php 
<?php
    // Outputs all POST parameters to a text file. The file name is the date_time of the report reception
    error_log("_REQUEST called " . print_r($_REQUEST,true),0);
    $fileName = 'acra/'.date('Y-m-d_H-i-s').'.txt';
    $file = fopen($fileName,'w') or die('Could not create report file: ' . $fileName);
    foreach($_POST as $key => $value) {
    $reportLine = $key." = ".$value."\n";
        fwrite($file, $reportLine) or die ('Could not write to report file ' . $reportLine);
    }
    fclose($file);
?>

任何人都可以说明为什么没有发生?

1 个答案:

答案 0 :(得分:0)

首先,您需要在名称前加.android:name=".ProspectApplication"

其次,你有这一行:

 mode = ReportingInteractionMode.TOAST

但你没有在吐司中展示的文字。您需要添加resToastId:

resToastText=R.string.errorMessage

或Toast中没有显示任何内容