简体   繁体   English

如何在intellij IDEA上使用proguard?

[英]How to use proguard on intellij IDEA?

I am using Intellij IDEA to develop java desktop application.我正在使用 Intellij IDEA 开发 java 桌面应用程序。 And I want to obfuscate my source code using proguard.我想使用 proguard 混淆我的源代码。 How to integrate/use proguard on Intellij IDEA 2016.1.14?如何在 Intellij IDEA 2016.1.14 上集成/使用 proguard?

1. add plugin Intellijguar2 1.添加插件Intellijguar2

在此处输入图片说明

2. in Project Structure ->modules->obfuscation press download yguard as it prompts. 2.项目结构->模块->混淆中按提示下载yguard It brings to a html page where yguard is placed next to right edge of the page.它带来了一个 html 页面,其中 yguard 被放置在页面的右边缘旁边。 Unzip.Get jar.解压,得到 jar。 Navigate to the jar.导航到罐子。 Set its path.设置其路径。 Uncheck pedantic error-checking (optionally) , define project's MainClass.取消选中pedantic error-checking (optional) ,定义项目的 MainClass。 Ok it.好的。

3. Build -> Build project -> build artifacts and get ordinary executable jar. 3. Build -> Build project -> build artifacts,得到普通的可执行jar。 (If you cannot see artifacts enabled in Run menu go to file-> project structure ->artfact and create by + new item with dependensy to the main class) (如果您看不到在运行菜单中启用的工件,请转到文件-> 项目结构-> 工件并通过 + 与主类相关的新项目创建)

4. build -> obfuscate *** module 4.构建->混淆 *** 模块

在此处输入图片说明

5. Add YourProject/out/production/YourProject/firstfolder_of_packagename containing your project's * .class files(mine was 'uz', eg) . 5.添加包含项目 * .class文件的YourProject/out/production/YourProject/firstfolder_of_packagename (mine YourProject/out/production/YourProject/firstfolder_of_packagename 'uz', eg) 。

6. Remove Module compile output Assign a path to the jar to be obfuscated below and press 'build' 6. Remove Module compile output为下面要混淆的jar分配一个路径,然后按'build'

7. Open obfuscated jar with zip program. 7.用 zip 程序打开混淆的 jar。 Make sure the class files are all obfuscated by JD-GUI app.确保类文件都被 JD-GUI 应用程序混淆了。

8. cut off META-INF folder and add META-INF one from executable inobfuscated jar and also folders like libs or assets(or find out them in artifacts you setup previously) manually. 8.切断 META-INF 文件夹并手动添加 META-INF 一个从可执行的非混淆jar 以及像库或资产这样的文件夹(或在您之前设置的工件中找到它们)。 In turn you'll get an obfuscated executable jar Eg for json lib finally I've got the result view in zip editor:反过来你会得到一个混淆的可执行 jar 例如 json lib 最后我在 zip 编辑器中得到了结果视图: 在此处输入图片说明

I have not tried this (i like to find the easy way first) but, it should work if you follow the steps.我还没有尝试过这个(我喜欢先找到简单的方法)但是,如果您按照步骤操作,它应该可以工作。 I will try this and report back.我会试试这个并报告。

  1. Go to this link and learn how to create an Ant build file for IntelliJ IDEA转到此链接并了解如何为 IntelliJ IDEA创建Ant 构建文件

  2. Go here to download yGuard去这里下载yGuard

  3. Unpack the yGuard archive and navigate to the doc directory.解压 yGuard 存档并导航到doc目录。

  4. There is an html "how to" file.有一个 html“如何”文件。 Read up on that, and you should be ready to release minified code.仔细阅读,您应该准备好发布缩小的代码。

  5. Optional: search the net for yGuard tips & tricks to get the most out of your builds.可选:在网络上搜索 yGuard 提示和技巧,以充分利用您的构建。

--- WORKING-NOTES --- --- 工作笔记 ---

[1.0] In IntelliJ 2017, there is an option to generate the Ant Build File on the build menu. [1.0] 在 IntelliJ 2017 中,构建菜单上有一个选项可以生成 Ant 构建文件。 Build->Generate Ant Build File The settings that work for me are single-build-file, with everything else checked, using the supplied project name. Build->Generate Ant Build File对我Build->Generate Ant Build File的设置是单个构建文件,使用提供的项目名称检查其他所有内容。

[1.1] View->Tool Windows->Ant Build this should get you where you need to be with the knowledge you got from the 5th step of the link at step 1 and step 4 of this answer. [1.1] View->Tool Windows->Ant Build这应该可以让您使用从本答案第1步和第4步链接的第 5 步中获得的知识。

Here is my working yGuard task:这是我的 yGuard 工作任务:

<target depends="artifact.project" name="yguard">
<taskdef name="yguard"
         classname="com.yworks.yguard.YGuardTask"
         classpath="yguard.jar"/>
<yguard>

  <inoutpair in="${temp.jar.path.project.jar}"
             out="${artifact.output.project}/project-release.jar"/>

    <shrink
            logfile="shrinklog.xml">
        <keep>
            <class classes="protected"
                   methods="protected"
                   fields="protected"/>
        </keep>
    </shrink>

</yguard>

Then you modify your "all" to look like this:然后你修改你的“全部”看起来像这样:

  <target name="all" depends="build.modules, build.all.artifacts, yguard"
          description="build all">
      <!-- Delete temporary files -->
      <delete dir="${artifacts.temp.dir}"/>

  </target>

And you have to REMOVE the delete temporary files action from the build.all.artifacts target, so when you get to the all target, the files are still available.并且您必须从build.all.artifacts目标中delete temporary files操作,因此当您到达all目标时,文件仍然可用。

Just like it says in the yGuard html doc at the bottom, IntelliJ will complain about your yGuard syntax, but yGuard will still work.就像底部的 yGuard html doc中所说的那样,IntelliJ 会抱怨您的 yGuard 语法,但 yGuard 仍然可以工作。

If anyone can clean this up, feel free.如果有人可以清理它,请随意。 It works for me, your mileage may vary.它对我有用,您的里程可能会有所不同。 Also, you WILL be able to create a really tiny ant build xml, and use the Project Structure->Artifacts->Post Processing , after you have added your "tiny" ant build as noted in WORKING-NOTES: [1.1] "5th step" .此外,您将能够创建一个非常小的 ant 构建 xml,并使用Project Structure->Artifacts->Post Processing ,在您添加了您的“微小”ant 构建后,如WORKING-NOTES: [1.1] "5th step" Some hand-hacking will definitely be required for this.为此,肯定需要一些手工操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM