2012-03-23 203 views
0

我知道如何proguard android項目,但目前我使用android做一個jar讓人們可以在android應用程序中使用我的jar,但我想我的jar到proguard .i使用proguard工具,我的pro文件是:如何proguard android jar

-libraryjars 'D:\Android\android-sdk\platforms\android-7\android.jar' 

-optimizationpasses 5 
-dontusemixedcaseclassnames 
-dontskipnonpubliclibraryclasses 
    -dontpreverify 
-verbose 
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 

-keep public class * extends android.app.Activity   
-keep public class * extends android.app.Application 
-keep public class * extends android.app.Service 
-keep public class * extends android.content.BroadcastReceiver 
-keep public class * extends android.content.ContentProvider 
-keep public class * extends android.app.backup.BackupAgentHelper 
-keep public class * extends android.preference.Preference 
-keep public class com.android.vending.licensing.ILicensingService 
-keep public abstract interface com.asqw.android.Listener{ 
public protected <methods>; 
} 

-keepclasseswithmembernames class * { 
native <methods>; 
} 
-keepclasseswithmembers class * { 
public <init>(android.content.Context, android.util.AttributeSet); 
} 
-keepclasseswithmembers class * { 
    public <init>(android.content.Context, android.util.AttributeSet, int); 
} 
-keepclassmembers class * extends android.app.Activity { 
public void *(android.view.View); 
} 

-keepclassmembers枚舉* { 公共靜態* []值(); public static * valueOf(java.lang.String);

} -keep class * implements android.os.Parcelable public static final android.os.Parcelable $ Creator *; } 它給了我成功,但是當我在我的應用程序中調用程序化的jar時,找不到一些類。

在我的項目中:它給我:import com.ant.liao.GifView.GifImageType; canot找到了。我gifView文件是:

public class GifView extends ImageView implements GifAction{ 


private GifDecoder gifDecoder = null; 

private Bitmap currentImage = null; 

private boolean isRun = true; 

private boolean pause = false; 

private DrawThread drawThread = null; 

private Context context = null; 

private boolean cacheImage = false; 

private View backView = null; 

private GifImageType animationType = GifImageType.SYNC_DECODER; 

public enum GifImageType{ 

    WAIT_FINISH (0), 

    SYNC_DECODER (1), 

    COVER (2); 

    GifImageType(int i){ 
     nativeInt = i; 
    } 
    final int nativeInt; 
} 


public GifView(Context context) { 
    super(context); 
    this.context = context; 
    //gifDecoder = new GifDecoder(this); 
    setScaleType(ImageView.ScaleType.FIT_XY); 
} 

public GifView(Context context, AttributeSet attrs) { 
    this(context, attrs,0); 

} 

public GifView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    this.context = context; 
    // TypedArray a = context.obtainStyledAttributes(attrs,R.array.); 
    //gifDecoder = new GifDecoder(this); 
    setScaleType(ImageView.ScaleType.FIT_XY); 
} 


private void setGifDecoderImage(byte[] gif){ 

    if(gifDecoder == null){ 
     gifDecoder = new GifDecoder(this); 
    } 
    gifDecoder.setGifImage(gif); 
    gifDecoder.start(); 
} 


private void setGifDecoderImage(InputStream is){ 

    if(gifDecoder == null){ 
     gifDecoder = new GifDecoder(this); 
    } 
    gifDecoder.setGifImage(is); 
    gifDecoder.start(); 


} 


public void setAsBackground(View v){ 
    backView = v; 
} 

protected Parcelable onSaveInstanceState() { 
    super.onSaveInstanceState(); 
    if(gifDecoder != null) 
     gifDecoder.free(); 

    return null; 
} 

//公共無效setCahceImage(){// 如果(gifDecoder == NULL){// = gifDecoder新GifDecoder(本); //} // cacheImage = true; // gifDecoder.setCacheImage(true,context); //}

public void setGifImage(byte[] gif){ 
    setGifDecoderImage(gif); 
} 


public void setGifImage(InputStream is){ 
    setGifDecoderImage(is); 
} 


public void setGifImage(int resId){ 
    Resources r = getResources(); 
    InputStream is = r.openRawResource(resId); 
    setGifDecoderImage(is); 
} 


public void destroy(){ 
    if(gifDecoder != null) 
     gifDecoder.free(); 
} 


public void showCover(){ 
    if(gifDecoder == null) 
     return; 
    pause = true; 
    currentImage = gifDecoder.getImage(); 
    invalidate(); 
} 


public void showAnimation(){ 
    if(pause){ 
     pause = false; 
    } 
} 


public void setGifImageType(GifImageType type){ 
    if(gifDecoder == null) 
     animationType = type; 
} 


public void parseOk(boolean parseStatus,int frameIndex){ 
    if(parseStatus){ 
     if(gifDecoder != null){ 
      switch(animationType){ 
      case WAIT_FINISH: 
       if(frameIndex == -1){ 
        if(gifDecoder.getFrameCount() > 1){  
         DrawThread dt = new DrawThread(); 
         dt.start(); 
        }else{ 
         reDraw(); 
        } 
       } 
       break; 
      case COVER: 
       if(frameIndex == 1){ 
        currentImage = gifDecoder.getImage(); 
        reDraw(); 
       }else if(frameIndex == -1){ 
        if(gifDecoder.getFrameCount() > 1){ 
         if(drawThread == null){ 
          drawThread = new DrawThread(); 
          drawThread.start(); 
         } 
        }else{ 
         reDraw(); 
        } 
       } 
       break; 
      case SYNC_DECODER: 
       if(frameIndex == 1){ 
        currentImage = gifDecoder.getImage(); 
        reDraw(); 
       }else if(frameIndex == -1){ 
        reDraw(); 
       }else{ 
        if(drawThread == null){ 
         drawThread = new DrawThread(); 
         drawThread.start(); 
        } 
       } 
       break; 
      } 

     }else{ 
      Log.e("gif","parse error"); 
     } 

    } 
} 

private void reDraw(){ 
    if(redrawHandler != null){ 
     Message msg = redrawHandler.obtainMessage(); 
     redrawHandler.sendMessage(msg); 
    } 

} 

private void drawImage(){ 
    setImageBitmap(currentImage); 
    invalidate(); 
} 

private Handler redrawHandler = new Handler(){ 
    public void handleMessage(Message msg) { 
     try{ 
      if(backView != null){ 
       backView.setBackgroundDrawable(new BitmapDrawable(currentImage)); 
      }else{ 
       drawImage(); 
      } 
     }catch(Exception ex){ 
      Log.e("GifView", ex.toString()); 
     } 
    } 
}; 

    private class DrawThread extends Thread{ 
    public void run(){ 
     if(gifDecoder == null){ 
      return; 
     } 
     while(isRun){ 
      if(gifDecoder.getFrameCount() == 1){ 

       GifFrame f = gifDecoder.next(); 
       currentImage = f.image; 
       gifDecoder.free(); 
       reDraw(); 

       break; 
      } 
      if (pause == false) { 
       GifFrame frame = gifDecoder.next(); 

       if (frame == null) { 
        SystemClock.sleep(50); 
        continue; 
       } 
       if (frame.image != null) 
        currentImage = frame.image; 
       else if (frame.imageName != null) { 
        currentImage = BitmapFactory.decodeFile(frame.imageName); 
       } 
       long sp = frame.delay; 
       if (redrawHandler != null) { 
        reDraw(); 
        SystemClock.sleep(sp); 
       } else { 
        break; 
       } 
      } else { 
       SystemClock.sleep(50); 
      } 
     } 
    } 
} 

} 當使用ProGuard工具ProGuard的文件,gf2.setGifImage(R.drawable.a2)I; gf2.setGifImageType(GifImageType.COVER); gf1.showCover()等等,所有的公共方法無法從罐子

回答

2

稱爲以下內容添加到您的proguard.config。我認爲這將有助於維護枚舉:

-keep public enum com.ant.liao.GifView.GifImageType$** { 
    **[] $VALUES; 
    public *; 
} 

或繞過它定義枚舉類:

-keep class com.ant.liao.GifView { *; } 
+0

我用1個方法沒有用。 – pengwang 2012-03-23 07:36:48

+0

第二個呢? – waqaslam 2012-03-23 07:37:39

+0

我用了2個方法它減少了我的錯誤,只找到了GifImageType.COVER,你能告訴我如何減少它嗎? – pengwang 2012-03-23 07:37:52

1

-injars GifView.jar -outjars G.jar

-libraryjars「 D:\ Android \ android-sdk \ platforms \ android-7 \ android.jar'

-optimizations!code/simplification/arithmetic,!field/,!class/merge/ -optimizationpasses 5 -dontusemixedcaseclassnames -dontpreverify -verbose

-keep公共類*寬android.app.Activity

-keep公共類*寬android.app.Application

-keep public class * extends android.app.Service

-keep public class * extends android.content.BroadcastReceiver

-keep public class * extends android.content.ContentProvider

-keep public class * extends android.app.backup。BackupAgentHelper

-keep公共類*寬android.preference.Preference

-keep公共類com.android.vending.licensing.ILicensingService -keep公共接口com.ant.liao.GifAction -keepclassmembers類COM .ant.liao.GifView { public void ); public void set *(*); public void show *();

} -keep class com.ant.liao.GifImageType {*; }

-keep public interface com.asqw.android.Listener { public protected; }

-keepclasseswithmembers class * {012.txt.txt,android.util.AttributeSet); }

-keepclasseswithmembers class * {012.txt.txt,android.util.AttributeSet,int); }

-keepclassmembers class * extends android.app.Activity { public void *(android.view.View); }

-keep class * extends android.os.Parcelable public static final android.os.Parcelable $ Creator *; }

還保留 - 枚舉。保留枚舉類所需的特殊靜態方法。

-keepclassmembers enum * { public static * [] values(); public static * valueOf(java.lang.String); }

保留名稱 - 原生方法名稱。保留所有原生類/方法名稱。

-keepclasseswithmember,allowhrinking class * { native; } 我得到了eunm出gifView java文件,並把eunm GifImageType作爲一個單獨的java文件