创建一个不显示代码的Java库。

huangapple go评论78阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年9月13日 18:08:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63869538.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定