Android Activity 自定义方法 不混淆,可以使用@Keep注解

Android Activity 自定义方法 不混淆

在Android开发中,如果你想要在Activity中添加一个自定义方法,并确保这个方法在混淆时不被混淆,你可以使用@Keep注解。这个注解来自于Google的androidx.annotation包。

以下是一个简单的例子:

import androidx.annotation.Keep;

import android.app.Activity;

import android.os.Bundle;

public class MyActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// 省略其他代码

}

@Keep

public void myCustomMethod() {

// 自定义方法的实现

}

}

在这个例子中,myCustomMethod方法被@Keep注解标记,这意味着在混淆时ProGuard不会混淆这个方法。这样,即使是在混淆后的APK中,这个方法依然可以被其他代码或反射调用。

相关推荐
百锦再6 小时前
React编程高级主题:测试代码
android·前端·javascript·react.js·前端框架·reactjs
2501_916008897 小时前
全面介绍Fiddler、Wireshark、HttpWatch、SmartSniff和firebug抓包工具功能与使用
android·ios·小程序·https·uni-app·iphone·webview
玉梅小洋8 小时前
Windows 10 Android 构建配置指南
android·windows
Libraeking10 小时前
视觉篇:Canvas 自定义绘图与高级动画的华丽圆舞曲
android·经验分享·android jetpack
Fushize10 小时前
多模块架构下的依赖治理:如何避免 Gradle 依赖地狱
android·架构·kotlin
Jomurphys11 小时前
Kotlin - 类型别名 typealias
android·kotlin
Haha_bj11 小时前
Flutter ——flutter_screenutil 屏幕适配
android·ios
Haha_bj11 小时前
Flutter ——device_info_plus详解
android·flutter·ios
前端小伙计11 小时前
Android/Flutter 项目统一构建配置最佳实践
android·flutter
Mr_sun.13 小时前
Day09——入退管理-入住-2
android·java·开发语言