百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

Stark

> 包管理
开源

Stark 是一个用于 Android 的热修复框架。它支持在不重启运行中的 Android 应用程序的情况下,交换新的类实现,并更新 Andr

362 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Stark 是一个用于 Android 的热修复框架。它支持在不重启运行中的 Android 应用程序的情况下,交换新的类实现,并更新 Andr

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

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

xml
    Resources bug
    

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:

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:

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:

java
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.

java
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

pro
-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

…

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

  • Read the Chinese wiki

Thinks

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

About Author

Pengfeng Wang(王鹏锋)

email: [email protected]

License

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaandroidgradlehot-fixpatch

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类包管理
定价开源

> 相关工具

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image