简体   繁体   中英

How to use proguard on intellij IDEA?

I am using Intellij IDEA to develop java desktop application. And I want to obfuscate my source code using proguard. How to integrate/use proguard on Intellij IDEA 2016.1.14?

1. add plugin Intellijguar2

在此处输入图片说明

2. in Project Structure ->modules->obfuscation press download yguard as it prompts. It brings to a html page where yguard is placed next to right edge of the page. Unzip.Get jar. Navigate to the jar. Set its path. Uncheck pedantic error-checking (optionally) , define project's MainClass. Ok it.

3. Build -> Build project -> build artifacts and get ordinary executable 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

在此处输入图片说明

5. Add YourProject/out/production/YourProject/firstfolder_of_packagename containing your project's * .class files(mine was 'uz', eg) .

6. Remove Module compile output Assign a path to the jar to be obfuscated below and press 'build'

7. Open obfuscated jar with zip program. Make sure the class files are all obfuscated by JD-GUI app.

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. In turn you'll get an obfuscated executable jar Eg for json lib finally I've got the result view in zip editor: 在此处输入图片说明

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

  2. Go here to download yGuard

  3. Unpack the yGuard archive and navigate to the doc directory.

  4. There is an html "how to" file. 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.

--- WORKING-NOTES ---

[1.0] In IntelliJ 2017, there is an option to generate the Ant Build File on the build menu. Build->Generate Ant Build File The settings that work for me are single-build-file, with everything else checked, using the supplied project name.

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

Here is my working yGuard task:

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

Just like it says in the yGuard html doc at the bottom, IntelliJ will complain about your yGuard syntax, but yGuard will still work.

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" . Some hand-hacking will definitely be required for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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