├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── cuieney │ │ └── autofix │ │ ├── App.java │ │ └── MainActivity.java │ └── res │ ├── drawable │ └── thumb.png │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ ├── ic_launcher_round.png │ └── thumb.jpg │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ ├── ic_launcher_round.png │ └── thumb.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── buildsrc ├── .gitignore ├── build.gradle ├── mavenpush.gradle └── src │ └── main │ ├── groovy │ └── com │ │ └── cuieney │ │ └── autofix │ │ ├── AutoFix.groovy │ │ ├── AutoFixExtension.groovy │ │ └── utils │ │ ├── AutoUtils.groovy │ │ ├── NuwaProcessor.groovy │ │ └── NuwaSetUtils.groovy │ └── resources │ └── META-INF │ └── gradle-plugins │ └── com.cuieney.autofix.properties ├── fix.zip ├── fix ├── .gitignore ├── build.gradle ├── mavenpush.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── Auto.dex │ ├── java │ │ └── com │ │ │ └── cuieney │ │ │ └── fix │ │ │ ├── AutoFix.java │ │ │ ├── AutoUtils.java │ │ │ └── DynamicApk.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── cuieney │ └── fix │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images └── patchdir.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## AutoFix 2 | >目前项目支持静态修复功能需要重启,集成简单,使用方便。 3 | 4 | ### 原理 5 | 这两篇文章就够了 6 | 7 | [DexClassLoader热修复的入门到放弃](https://juejin.im/post/5951d5265188250d8f602225) 8 | 9 | [手把手教你写热修复(HOTFIX)](https://juejin.im/post/595d02d5f265da6c375a90bf) 10 | 11 | ## 集成 12 | ### Get Gradle Plugin 13 | 1. 根据以下操作把代码填到你项目根目录的gradle中 14 | >classpath 'com.cuieney:autofix:1.1.1' 15 | 16 | build.gradle maybe look like this: 17 | 18 | ``` 19 | buildscript { 20 | repositories { 21 | jcenter() 22 | } 23 | dependencies { 24 | classpath 'com.android.tools.build:gradle:2.3.0' 25 | classpath 'com.cuieney.autofix:gradle:1.1.7' 26 | } 27 | } 28 | ``` 29 | 2. 在你的build.gradle:中添加这样的代码块 30 | 31 | >apply plugin: "com.cuieney.autofix" 32 | 33 | ### Get AutoFix SDK 34 | 35 | * gradle dependency: 36 | 37 | ``` 38 | dependencies { 39 | compile 'com.cuieney.library:fix:1.1.2' 40 | } 41 | ``` 42 | 43 | ### 使用步骤 44 | 1. 在你的application中添加一下代码初始化: 45 | 46 | ``` 47 | @Override 48 | protected void attachBaseContext(Context base) { 49 | super.attachBaseContext(base); 50 | AutoFix.init(this); 51 | } 52 | ``` 53 | 2. 如果你需要加载补丁的话可以这样,每次需需要重启: 54 | 55 | ``` 56 | AutoFix.applyPatch(this,patch.jar); 57 | 58 | ``` 59 | 60 | ### ProGuard 61 | * 添加到你的proguardFile文件中: 62 | 63 | >-keep class cn.cuieney.fix.** { *; } 64 | 65 | ## 补丁制作 66 | 根据下面三步即可以完成补丁的制作 67 | 68 | 1.首选你的添加`auto_fix`extension到你的build.gradle中,只在你需要制作补丁的时候才用得到(不制作补丁注释即可) 69 | 70 | ``` 71 | auto_fix { 72 | lastVersion = '1'//顾名思义,上次一的版本号(就是说你当前Version是1,出现bug了,你把versioncode变成了2)然后这个lastVersion就填1 73 | } 74 | 75 | ``` 76 | 77 | 2.现在你已经改好bug了,需要获取相应的patch.jar把这个补丁打到app中,只需要编译一下项目即可,buildApk这个操作也是可以的 78 | 79 | 3.获取补丁push到手机中(如果项目已上线即push到服务器) 80 | 81 | 82 | ![Screen Shot 2017-07-05 at 8.20.17 PM.png](http://upload-images.jianshu.io/upload_images/3415839-1a5eb39c9d2f0ad8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 83 | 84 | 这个就是你的补丁对应的目录,patch.jar就是补丁包(version `2`)代表你生成补丁当前的版本号 85 | 86 | ### TODO 87 | - 增强兼容性 88 | - 支持runtime 89 | - 增加插件化跳转Act 90 | 91 | ### 补充 92 | 你会看到AutoFix SDK里面有这样一个类DynamicApk,这是一个beta版。用于插件化的工具。目前focus获取apk的资源文件,目前接口如下: 93 | - getStringFromApk 94 | - getBitmapFromApk 95 | - getDrawableFromApk 96 | - getMipmapFromApk 97 | - getLayoutFromApk 98 | - getColorFromApk 99 | - getDimenFromApk 100 | 101 | 参数都一样(Context context, String apkPath, String name),只介绍最后一个参数such as(R.drawable.thumb)这个name就是thumb 102 | 103 | 104 | #### 问题 105 | 发现bug或好的建议欢迎 [issues](https://github.com/Cuieney/AutoFix/issues) or 106 | Email 107 | ### License 108 | F**K License 109 | 110 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.cuieney.autofix' 3 | repositories { 4 | jcenter() 5 | } 6 | android { 7 | compileSdkVersion 25 8 | buildToolsVersion "25.0.2" 9 | defaultConfig { 10 | applicationId "com.cuieney.autofix" 11 | minSdkVersion 19 12 | targetSdkVersion 25 13 | versionCode 2 14 | versionName "1.0" 15 | } 16 | 17 | 18 | 19 | buildTypes { 20 | debug { 21 | minifyEnabled true //代码混淆处理 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | 25 | release { 26 | minifyEnabled true 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | } 31 | auto_fix { 32 | lastVersion = '1' 33 | } 34 | 35 | dependencies { 36 | compile fileTree(include: ['*.jar'], dir: 'libs') 37 | compile 'com.android.support:appcompat-v7:25.2.0' 38 | testCompile 'junit:junit:4.12' 39 | compile 'com.cuieney.library:fix:1.1.2' 40 | } 41 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/baidu/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | -keep class com.cuieney.fix.** {*;} 20 | -keepattributes EnclosingMethod -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/cuieney/autofix/App.java: -------------------------------------------------------------------------------- 1 | package com.cuieney.autofix; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.os.Environment; 6 | 7 | import com.cuieney.fix.AutoFix; 8 | 9 | /** 10 | * Created by cuieney on 29/06/2017. 11 | */ 12 | 13 | public class App extends Application { 14 | @Override 15 | protected void attachBaseContext(Context base) { 16 | super.attachBaseContext(base); 17 | AutoFix.init(this); 18 | AutoFix.applyPatch(this,Environment.getExternalStorageDirectory().getAbsolutePath()+"/patch.jar"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/cuieney/autofix/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.cuieney.autofix; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.res.AssetManager; 6 | import android.content.res.Resources; 7 | import android.graphics.BitmapFactory; 8 | import android.os.Environment; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.os.Bundle; 11 | import android.util.Log; 12 | import android.view.View; 13 | import android.widget.ImageView; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.cuieney.fix.DynamicApk; 18 | 19 | import java.io.File; 20 | import java.lang.reflect.Field; 21 | import java.lang.reflect.InvocationTargetException; 22 | import java.lang.reflect.Method; 23 | 24 | import dalvik.system.DexClassLoader; 25 | 26 | public class MainActivity extends Activity { 27 | 28 | private TextView test; 29 | private ImageView image; 30 | private Activity context; 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_main); 35 | context = this; 36 | 37 | final String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/dynamic.apk"; 38 | 39 | test = (TextView) findViewById(R.id.test); 40 | test.setOnClickListener(new View.OnClickListener() { 41 | @Override 42 | public void onClick(View view) { 43 | String app_name = DynamicApk.getStringFromApk(context, path, "app_name"); 44 | Toast.makeText(context, app_name, Toast.LENGTH_SHORT).show(); 45 | test.setTextColor(DynamicApk.getColorFromApk(context,path,"colorAccent")); 46 | image.setImageBitmap(BitmapFactory.decodeResource(DynamicApk.getResource(context,path),DynamicApk.getDrawableFromApk(context,path,"thumb"))); 47 | 48 | } 49 | }); 50 | image = ((ImageView) findViewById(R.id.image)); 51 | 52 | image.setImageResource(R.drawable.thumb); 53 | 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuieney/AutoFix/98c21f3022eb24e299788d4bee67a7cc9de3a976/app/src/main/res/drawable/thumb.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 |