在Android Studio中混淆文件夹结构,包

时间:2017-02-01 06:33:59

标签: android proguard

我的SampleApp已成功进行模糊处理,但遗憾的是没有对于pacakges,文件夹等。我的应用包含名称为' service',' activity',' receiver' '恒定''分贝'在android包文件夹下等。请帮帮我。

我已经提到了这个链接,但不适合我。 Obfuscate the folder structure - Android

模块级build.gradle

apply plugin: 'com.android.application'

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.22.0'
    }

}

repositories
        {
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.android"
        minSdkVersion 14
        targetSdkVersion 24
        versionCode 1
        versionName "1.0.0"
        // Enabling multidex support.
        multiDexEnabled true

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

    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    externalNativeBuild {
        cmake {
            path 'CMakeLists.txt'
        }
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':commons')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.squareup:otto:1.3.8'
    compile 'uk.co.chrisjenx:calligraphy:2.2.0'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'

proguard-rules文件:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\ANDROID-DEV\AndroidStudioSDK/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 *;
#}

#-ignorewarnings
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-dontshrink
-verbose

-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

#-injars bin/classes
#-injars libs
#outjars bin/classes-processed.jar
#-libraryjars libs(!META-INF/MANIFEST.MF,!META-INF/LICENSE.txt)

-repackageclasses ''
-keepattributes Signature
-printmapping out.map
-renamesourcefileattribute SourceFile



-keep public class * extends android.imgView.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

# my rules
#-repackageclasses 'myobfuscated'
#-allowaccessmodification


#-dontshrink
#-dontoptimize




# Keep fragments


# Serializables


# Native Methods



# Android Support Library



# Button methods



# Reflection

-keepclassmembers class com.elsinga.sample.proguard.SensorDescriptionFragment {

public void updateFields(com.elsinga.sample.proguard.SensorData);

}

# Remove Logging
-assumenosideeffects class android.util.Log {
    public static *** e(...);
    public static *** w(...);
    public static *** wtf(...);
    public static *** d(...);
    public static *** v(...);
}

#-libraryjars libs




# The official support library.
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
-keep class android.support.multidex.** { *; }
-keep interface android.support.multidex.** { *; }
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }

# Library JARs.

-keepattributes SourceFile,LineNumberTable
-keep class com.parse.*{ *; }
-dontwarn com.parse.**
-dontwarn com.squareup.picasso.**
-keepclasseswithmembernames class * {
    native <methods>;
}

-keep class twitter4j.** { *; }
-keep interface twitter4j.** { *; }
-keep class com.google.gson.** { *; }
-keep interface com.google.gson.** { *; }
-keep class org.xmlpull.v1.** { *; }
-keep interface org.xmlpull.v1.** { *; }
-keep class org.ksoap2.** { *; }
-keep interface org.ksoap2.** { *; }
-keep class org.kxml2.** { *; }
-keep interface org.kxml2.** { *; }
-keep class org.kobjects.** { *; }
-keep interface org.kobjects.** { *; }
-keep class com.google.android.gcm.** { *; }
-keep interface com.google.android.gcm.** { *; }
-keep class com.google.analytics.** { *; }
-keep interface com.google.analytics.** { *; }
-keep class com.google.tagmanager.** { *; }
-keep interface com.google.tagmanager.** { *; }
-keep class com.google.gson.** { *; }
-keep interface com.google.gson.** { *; }
-keep class com.google.** { *; }
-keep interface com.google.** { *; }
-keep class com.google.android.youtube.player.** { *; }
-keep interface com.google.android.youtube.player.** { *; }
#-keep class com.googlecode.flickrjandroid.** { *; }
#-keep interface com.googlecode.flickrjandroid.** { *; }

# Library projects.
#-keep class com.winjit.newslib.** { *; }
#-keep interface com.winjit.newslib.** { *; }
-keep class com.facebook.** { *; }
-keep interface com.facebook.** { *; }
-keep class bolts.** { *; }
-keep interface bolts.** { *; }
-keep class com.google.** { *; }
-keep interface com.google.** { *; }
-keep class com.viewpagerindicator.** { *; }
-keep interface com.viewpagerindicator.** { *; }
-keep class com.jeremyfeinstein.slidingmenu.lib.** { *; }
-keep interface com.jeremyfeinstein.slidingmenu.lib.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep class com.handmark.pulltorefresh.library.** { *; }
-keep interface com.handmark.pulltorefresh.library.** { *; }
-keep class com.costum.android.widget.** { *; }
-keep interface com.costum.android.widget.** { *; }
-keep class com.nirhart.parallaxscroll.** { *; }
-keep interface com.nirhart.parallaxscroll.** { *; }
-keep class org.askerov.dynamicgrid.** { *; }
-keep interface org.askerov.dynamicgrid.** { *; }
-keep class com.melnykov.fab.** { *; }
-keep interface com.melnykov.fab.** { *; }
-keep class com.nineoldandroids.** { *; }
-keep interface com.nineoldandroids.** { *; }
-keep class com.andexert.library.** { *; }
-keep interface com.andexert.library.** { *; }
-keep class com.indris.material.** { *; }
-keep interface com.indris.material.** { *; }
-keep class com.nostra13.universalimageloader.** { *; }
-keep interface com.nostra13.universalimageloader.** { *; }
-keep class com.android.volley.** { *; }
-keep interface com.android.volley.** { *; }

-keep class com.xgc1986.parallaxpagerlibrary.** { *; }
-keep interface com.xgc1986.parallaxpagerlibrary.** { *; }

-keep class com.tooleap.sdk.** { *; }
-keep interface com.tooleap.sdk.** { *; }
-keep class me.grantland.widget.** { *; }
-keep interface me.grantland.widget.** { *; }

-keep class android.view.ext.** { *; }
-keep interface android.view.ext.** { *; }
-keep class com.getbase.floatingactionbutton.** { *; }
-keep interface com.getbase.floatingactionbutton.** { *; }
-keep class com.h6ah4i.android.widget.advrecyclerview.** { *; }
-keep interface com.h6ah4i.android.widget.advrecyclerview.** { *; }
-keep class com.astuetz.pagerslidingtabstrip.** { *; }
-keep interface com.astuetz.pagerslidingtabstrip.** { *; }
-keep class android.support.v7.widget.RoundRectDrawable { *; }
-keep class jp.wasabeef.** { *; }
-keep interface jp.wasabeef.** { *; }
-keep class com.aphidmobile.flip.** { *; }
-keep interface com.aphidmobile.flip.** { *; }
-keep class se.emilsjolander.flipview.** { *; }
-keep interface se.emilsjolander.flipview.** { *; }


-keep class com.squareup.otto.** { *; }
-keep interface com.squareup.otto.** { *; }

-keep class retrofit.** { *; }
-keep interface retrofit.** { *; }


-keep class okio.** { *; }
-keep interface okio.** { *; }

-keep class com.shemaroo.** { *; }
-keep interface com.shemaroo.** { *; }

#start crashlytics
-keep public class * extends java.lang.Exception
-printmapping mapping.txt
-keep class io.fabric..** {*; }
#end crasshlytics

#Start vmax Ads settings_help
-keep public class com.vmax.android.ads.**  { *; }
-keep class com.vmax.android.ads.mediation.partners.** { *; }
-keep interface com.vmax.android.ads.mediation.partners.** { *; }
-keep class com.vmax.android.ads.mediation.partners.** { *; }
-keep public class com.google.android.gms.**  { *; }
-keep public interface com.google.android.gms.**  { *; }
-keep class com.google.android.gms.ads.** { *; }
-dontwarn com.google.android.gms.**
 -keep class * extends java.util.ListResourceBundle { *; }
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { *; }
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * { @com.google.android.gms.common.annotation.KeepName *; }
-keepnames class * implements android.os.Parcelable { public static final ** CREATOR; }
-keep class com.facebook.** { *; }
#End vmax ads settings_help

-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

# If in your rest service interface you use methods with Callback argument.
-keepattributes Exceptions

# If your rest service methods throw custom exceptions, because you've defined an ErrorHandler.
-keepattributes Signature


-dontwarn rx.Observable$OnSubscribe
-dontwarn rx.Observable
-dontwarn rx.Subscriber
-dontwarn rx.subscriptions.Subscriptions
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn java.nio.file.Files
-dontwarn java.nio.file.Path
-dontwarn java.nio.file.OpenOption
-dontwarn com.google.appengine.api.urlfetch.HTTPMethod
-dontwarn com.google.appengine.api.urlfetch.URLFetchServiceFactory
-dontwarn com.google.appengine.api.urlfetch.URLFetchService
-dontwarn com.google.appengine.api.urlfetch.HTTPRequest
-dontwarn com.google.appengine.api.urlfetch.HTTPResponse
-dontwarn com.google.appengine.api.urlfetch.HTTPHeader
-keep class org.spongycastle.** { *; }
-keep class org.bouncycastle.** { *; }
-keep class org.xmlpull.v1.** { *; }

-keep class com.itextpdf.** { *; }
-dontwarn org.spongycastle.**

-keep class com.daimajja.** { *; }

-dontwarn org.spongycastle.**
-dontwarn java.awt.**
-dontwarn java.xml.**
-dontwarn javax.**
-dontwarn org.apache.**

-dontwarn org.bouncycastle.**

1 个答案:

答案 0 :(得分:2)

这是预期的行为。 ProGuard不会混淆以下类:

  1. 是顶级组件,如活动,服务,BroadcastReceiver等,如in this article所述。

  2. 拥有与其姓名相符的-keep规则。例如,类com.elsinga.sample.proguard.SensorDescriptionFragment不会被混淆,因为您有一个明确保留它的ProGuard规则。

  3. 使用@Keep注释的类。

  4. 如果您认为ProGuard应该混淆某个类(例如com.example.SomeClass)但由于某种原因它不是,那么您可以在ProGuard配置文件中添加-whyareyoukeeping com.example.SomeClass以打印原因为什么没有进行混淆。