英文:
create java library that don't display code
问题
我想创建一个包含视图、适配器、SQLite、库等内容的Java库...
但我希望用户无法访问我的库代码。
实际上只能看到方法名称的接口,仅用于调用。
我该如何做到这一点?
英文:
I want to create a java library that contains the view, adapter, SQLite, libraries and etc...
but I want the user can't access my library's code.
Actually see an interface of method names just for calling.
how can I do it?
答案1
得分: 0
没有简单而强大的方法来防止Java类的反编译。然而,有许多用于Java的'混淆器'工具在实践中相当接近。
英文:
There is no simple, robust way to prevent decompilation of Java classes. However, there are many 'obfuscator' tools for Java that come pretty close in practice.
答案2
得分: 0
没有办法完全保护你的源代码,尤其是在Java中。你只能让其他人难以获取你的源代码。
第一种方法: 一个主要的技巧是使用像Proguard
这样的工具进行代码混淆。你可以通过在Gradle中添加属性minifyEnabled true
来启用它:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
使用这种技术,你需要排除用户需要与之交互的类。在Proguard配置文件中:
-keep class com.example.myapp.ThisParticularClass
第二种方法: 你可以使用另一种技巧,即向你的库添加一些C/C++代码。你可以在C/C++类中执行一些特定任务,如构建字符串、特殊字符、存储密钥和数字,然后在Java中调用这些类。
第三种方法: 尽管看起来很蠢,但确实有效。许多反编译你的代码的程序员不够认真,不愿花很多时间理解你的代码。因此,你可以通过使用接口、中间方法、额外的调用和一堆其他创新方法向你的项目/库中添加额外的样板代码。
英文:
There is no way to fully protect your source code, especially in Java. You can just make it hard for others to get to your source code.
First method: One major technique is code obfuscation using tools like Proguard
. You can enable it by adding the attribute minifyEnabled true
to your gradle:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Using this technique, you have to exclude the classes to which user needs to interact. In the proguard config file:
-keep class com.example.myapp.ThisParticularClass
Second method: Another technique that you can use is adding a bit of C/C++ code to your library. You can do some specific tasks like building Strings, special characters, storing keys and numbers in a C/C++ class and then in your java, call those classes.
Third method: While it seems stupid, but it really works. A lot of programmers who decompile your code are not serious enough to spend a lot of time understanding your code. So you can add extra boilerplate code to your project/library by using interfaces, intermediate methods, extra calls and a bunch of other innovative methods.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论