• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ximsfei/Stark: Stark is a hot-fix framework for Android. It supports swapping ne ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

ximsfei/Stark

开源软件地址(OpenSource Url):

https://github.com/ximsfei/Stark

开源编程语言(OpenSource Language):

Java 67.5%

开源软件介绍(OpenSource Introduction):

logo

release build pr license

Stark is a hot-fix framework for Android. It supports swapping new implementations of classes without restarting a running Android application, and updated Android resources (icons, layout, etc) while only restarting the Android Activity.

Sample Usage

  1. git clone https://github.com/ximsfei/Stark.git
  2. cd Stark
  3. ./gradlew :stark-sample:clean :stark-sample:assembleDebug
  4. adb install -r stark-sample/build/outputs/apk/debug/stark-sample-debug.apk
  5. Launch sample APK.
  6. Fix code and resources.

Fix Code

SecondActivity.java

public class SecondActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        content.setText("Code bug");
//        content.setText("aha, Code Bug Fix");
//        Toast.makeText(this, "fixed", Toast.LENGTH_SHORT).show();
    }
}

Fix Resources

strings.xml

    <string name="fix_text">Resources bug</string>
    <!--<string name="fix_text">Aha, Resources Bug Fix</string>-->

Change the TextView in activity_main.xml and activity_second.xml to Button.

  1. ./gradlew :stark-sample:clean :stark-sample:starkGeneratePatchDebug
  2. adb push stark-sample/build/outputs/apk/debug/stark-sample-debug.patch /sdcard/Android/data/com.ximsfei.stark.app/fix.apk
  3. Launch sample APK.
  4. Click the Button of applyPatch.
  5. Click the Button of recreate.
  6. Observe whether the code and resources are fixed.

Getting Started

The Gradle Dependency is available via jCenter,

Firstly, add dependency directly in your root project's build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.ximsfei:stark-gradle:0.0.5'
    }
}

Secondly, apply com.ximsfei.stark plugin and add stark core dependencies in your Android application project's build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.ximsfei.stark'

dependencies {
    implementation 'com.ximsfei:stark-core:0.0.5'
    implementation 'io.sigpipe:jbsdiff:1.0'
}

Note: Stark depends on jbsdiff, you need add jbsdiff dependency in your build.gradle

Initialize stark framework in application's attachBaseContext:

public class YourApp extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        Stark.get().load(base);
    }
}

After got the patch file, invoke the applyPatchAsync method to apply patch.

public class AnyClass {
    public void applyPatch(Context context, String path) {
        Stark.get().applyPatchAsync(context, path);
    }
}

After adding the dependencies and apply plugin, refresh gradle project, stark plugin will add two more tasks for you:

You can find them in the gradle stark task group.

  1. starkBackup + BuildType

After running the assemble + BuildType, run the backup task can backup the files needed to generate the patch for you.

Even you can enable an automatic backup configuration in the stark.properties file.

  1. starkGeneratePatch + BuildType

When you find a bug in an online apk, you can fix the code and run the starkGeneratePatch + BuildType task to generate hot-fix patch.

The starkGeneratePatch + BuildType task relies on files backed up by the starkBackup + BuildType task.

ProGuard

-keep class com.ximsfei.stark.core.runtime.** {public *;}

Configuration files

Also, the stark plugin will generate two configuration files in your Android application project dir:

stark.properties

# If autoBackup is true.
# Stark plugin will automatically backup the files needed to generate the patch.
# Otherwise, you need to run the stark backup task manually.
autoBackup=false

# If allStark is true.
# Stark plugin will inject redirection code into all BuildType(debug/release).
# You'd better disable this configuration at the development stage.
allStark=false

# If releaseStark is true.
# Stark plugin will inject redirection code into release stage.
releaseStark=true

# If your project needs to use multidex.
# You'd better get rid of the `multiDexEnabled = true` in build.gradle and enable it here.
multiDexEnabled=false

stark-rules.txt

# Add project specific stark rules here.
# include packages that need  to be fixed in the future.
# exclude packages that never to be fixed in the future.

-include: applicationId.

-exclude: android.support.

Contributing

For more information about contributing, see our contributing guide.

More

Thinks

Thanks to InstantRun, Tinker, Small, jbsdiff and Robust.

About Author

Pengfeng Wang(王鹏锋)

email: [email protected]

License




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ebean-orm/examples: Example use Ebean with Maven, Gradle, Java and Kotlin发布时间:2022-06-14
下一篇:
lenala/azure-gradle-plugins发布时间:2022-06-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap