Android热修复Java类_Nuwa 纯Java实现,可以用于热修复您的Android应用程序

687474703a2f2f376676696f762e636f6d312e7a302e676c622e636c6f7564646e2e636f6d2f6e7577612e6a7067

Nuwa

68747470733a2f2f6170692e62696e747261792e636f6d2f7061636b616765732f6a61736f6e726f73732f6d6176656e2f6e7577612f696d616765732f646f776e6c6f61642e737667

Nuwa is a goddess in ancient Chinese mythology best known for repairing the pillar of heaven.

With this Nuwa project,you can also have the repairing power, fix your android applicaiton without have to publish a new APK to the appstore.

Features

Support both dalvik and art runtime.

Support productFlavor and buildType.

Support proguard and multidex.

Pure java implementation.

Run the Sample

in master branch, run and install the app.

it shows『hello world』.

copy sample/build/outputs/nuwa dir to somewhere for later use.

for example: /Users/jason/Documents/nuwa

change to bugfix branch, run the following command in terminal to generate patch.jar.

./gradlew clean nuwaQihooDebugPatch -P NuwaDir=/Users/jason/Documents/nuwa

java verison must be same using android studio and terminal

run following command to push patch.jar to sdcard.

adb push sample/build/outputs/nuwa/qihoo/debug/patch.jar /sdcard/

restart your application (kill the process).

it shows『patch success』.

Integration

Get Gradle Plugin

add following to the build.gradle of your root project.

classpath 'cn.jiajixin.nuwa:gradle:1.2.2'

build.gradle maybe look like this:

```

buildscript {

repositories {

jcenter()

}

dependencies {

classpath 'com.android.tools.build:gradle:1.2.3'

classpath 'cn.jiajixin.nuwa:gradle:1.2.2'

}

}

```

add following to your build.gradle:

apply plugin: "cn.jiajixin.nuwa"

Get Nuwa SDK

gradle dependency: dependencies {

compile 'cn.jiajixin.nuwa:nuwa:1.0.0'

}

Use Nuwa SDK

add following to your application class: @Override

protected void attachBaseContext(Context base) {

super.attachBaseContext(base);

Nuwa.init(this);

}

load the patch file according to your needs: Nuwa.loadPatch(this,patchFile)

I plan to provide the management of patch file later.

ProGuard

add follwing to you proguardFile if you are using proguard:

-keep class cn.jiajixin.nuwa.** { *; }

Nuwa DSL

You can add nuwa extension to your build.gradle. Generally, you don't need this. nuwa{

}

Nuwa extension support following DSL object.

includePackage:HashSet

The internal name of a class is its fully qualified name, where '.' are replaced by '/'. For example:

cn/jiajixin/nuwasample/MainActivity.class

Using includePackage,you can only fix those classes whose internal name starts with includePackage.For example:

includePackage = ['cn/jiajixin/nuwasample'] Default, Nuwa can fix classes which not from the android support library.

excludeClass:HashSet

All Application subclasses should not be injected by Nuwa.

Default, Nuwa will automatically exclude the application declared in your manifest file. You need to exclude others using excludeClass

Using excludeClass, you can not fix those classes whose internal name ends with excludeClass.For example:

excludeClass = ['BaseApplication.class']

debugOn:boolean

whether use Nuwa in debug mode, default totrue.

Generate Patch

For how to generate patch file, please reference the first three steps of Run the Sample.

There are two types of gradle task to generate patch file:

nuwaPatches

this task will generate multi patch.jar for all variant.

nuwa${variant.name.capitalize()}Patch

this task will generate one patch.jar for specific variant.

How it Works

Inspired by QZone hotfix solution from this article.

inject into all classes one java bytecode referring the Hack.class from a different dex, which can avoid CLASS_ISPREVERIFIED error when replacing class.

generate patch.jar according to mapping.txt and classes hash of last published APK.

Nuwa

inject the Hack.class.

inject the patch.jar into head of BaseDexClassLoader's pathList.

Later Plan

provide patch file management

improve security of Nuwa

License

Copyright (c) 2015, jiajixin.cn

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值