2014-09-10 71 views
1

在ACRA網站上有一個關於使用ACRA和ProGuard和Eclipse的指南:https://github.com/ACRA/acra/wiki/ProGuard的Android ACRA和ProGuard的

在我來說,我使用Android Studio和我不是Java專家,但是我需要添加ACRA支持我的應用程序。我只是編輯了我的項目,但我不明白如何在Android Studio中設置ProGuard與ACRA配合使用,因此在我的發佈應用程序中,ACRA不起作用。

您可以解釋Eclipse轉換爲Android Studio步驟嗎?

回答

3

你有一個現有的eclipse項目,並希望在Android Studio中導入它?

如果不是這裏的解決方案:

你的build.gradle(一個是「應用程序」文件夾)的文件應該是這個樣子:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 20 
    buildToolsVersion '20.0.0' 

    defaultConfig { 
     applicationId "com.yourapp" 
     minSdkVersion 14 
     targetSdkVersion 20 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      runProguard true//make this true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile project(':library') 
    compile 'ch.acra:acra:4.5.0'//add this line here 
} 

和你proguard-rules.pro :

# Add project specific ProGuard rules here. 
# By default, the flags in this file are appended to flags specified 
# in C:\Android\AndroidSDKBundle2014-03-21x64\sdk/tools/proguard/proguard-android.txt 
# You can edit the include path and order by changing the proguardFiles 
# directive in build.gradle. 
# 
# For more details, see 
# http://developer.android.com/guide/developing/tools/proguard.html 

# Add any project specific keep options here: 

# If your project uses WebView with JS, uncomment the following 
# and specify the fully qualified class name to the JavaScript interface 
#class: 
-keepclassmembers class fqcn.of.javascript.interface.for.webview { 
    public *; 
} 


#ACRA specifics 
# Restore some Source file names and restore approximate line numbers in the stack traces, 
# otherwise the stack traces are pretty useless 
-keepattributes SourceFile,LineNumberTable 

# ACRA needs "annotations" so add this... 
# Note: This may already be defined in the default "proguard-android-optimize.txt" 
# file in the SDK. If it is, then you don't need to duplicate it. See your 
# "project.properties" file to get the path to the default "proguard-android-optimize.txt". 
-keepattributes *Annotation* 

# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'. 
# Note: if you are removing log messages elsewhere in this file then this isn't necessary 
-keep class org.acra.ACRA { 
    *; 
} 

# keep this around for some enums that ACRA needs 
-keep class org.acra.ReportingInteractionMode { 
    *; 
} 

-keepnames class org.acra.sender.HttpSender$** { 
    *; 
} 

-keepnames class org.acra.ReportField { 
    *; 
} 

# keep this otherwise it is removed by ProGuard 
-keep public class org.acra.ErrorReporter { 
    public void addCustomData(java.lang.String,java.lang.String); 
    public void putCustomData(java.lang.String,java.lang.String); 
    public void removeCustomData(java.lang.String); 
} 

# keep this otherwise it is removed by ProGuard 
-keep public class org.acra.ErrorReporter { 
    public void handleSilentException(java.lang.Throwable); 
} 

其餘的就像日食。

0

你的Android Studio項目應該有一個proguard-rules.txt文件。您需要在該文件中添加一些指令,以告知ProGuard要保留的內容,並參照ACRA指令中的ProGuard指令。

大多數情況下,您會將ACRA的內容proguard-project.txt複製到您項目的proguard-rules.txt文件中。

您可能需要添加一些指令,該ACRA指示預計將在Eclipse中的ProGuard配置文件中的基本文件proguard-android-optimize.txt如該文件從Android Studio中的文件不同android-studio\sdk\tools\proguard\proguard-android-optimize.txt

proguard-android-optimize.txt一個例子指令:

-keepclasseswithmembernames class * { 
    native <methods>; 
} 

這告訴ProGuard保持每個具有本地方法的類。