What we'll do is use a Java program called ProGuard to apply its magic to your program's code, during the build process. To do this we'll use an Ant script to build the program, and add our extra steps into the regular build process.
Why do it?
The short answer is that your code will be smaller and faster. How much smaller and faster depends, but in general you'll find your code will be a lot smaller and a little faster. There are three key functions that ProGuard will do. Much of the text below is taken from the ProGuard website.You may hear the term obfuscation to describe all three processes. Actually, obfuscation is just one form of the processes that a program such as ProGuard does. Instead of saying "shrink, obfuscate, and optimize", we'll just use the simple term of obfuscation to describe all three in this blog.
Shrinking
Java source code (.java files) is typically compiled to bytecode (.class files). Bytecode is more compact than Java source code, but it may still contain a lot of unused code, especially if it includes program libraries. Shrinking programs such as ProGuard can analyze bytecode and remove unused classes, fields, and methods. The program remains functionally equivalent, including the information given in exception stack traces.For a realistic example, take the following code:
if (Config.LOGGING) { TestClass test = new TestClass(); Log.d(TAG, "[onCreate] testClass=" + test); }
Config.LOGGING
to false
, so it doesn't execute. The problem is, this code is still in your application. It makes it bigger, and may cause potential security issues by including code which should never be seen by a snooping hacker. Shrinking the code solves this problem beautifully. The code is completely removed from the final product, leaving the final package safer and smaller.
Obfuscation
By default, compiled bytecode still contains a lot of debugging information: source file names, line numbers, field names, method names, argument names, variable names, etc. This information makes it straightforward to decompile the bytecode and reverse-engineer entire programs. Sometimes, this is not desirable. Obfuscators such as ProGuard can remove the debugging information and replace all names by meaningless character sequences, making it much harder to reverse-engineer the code. It further compacts the code as a bonus. The program remains functionally equivalent, except for the class names, method names, and line numbers given in exception stack traces.Optimizing
Apart from removing unused classes, fields, and methods in the shrinking step, ProGuard can also perform optimizations at the bytecode level, inside and across methods. Thanks to techniques like control flow analysis, data flow analysis, partial evaluation, static single assignment, global value numbering, and liveness analysis, ProGuard can do things such as perform over 200 peephole optimizations, like replacingx * 2
with x << 1
. The positive effects of these optimizations will depend on your code and on the virtual machine on which the code is executed. Simple virtual machines may benefit more than advanced virtual machines with sophisticated JIT compilers. At the very least, your bytecode may become a bit smaller. Using Ant to build your project
When you create your Android application, or build it, there are many steps involved. First, a Java compiler compiles the source files (i.e. the textual.java
files) into Java bytecode (i.e. .class
files). Then, a tool in the Android SDK turns the Java bytecode into Dalvik bytecode (i.e. .dex
files). Finally, all of the resources and code are packaged into a single ZIP file, which is an .APK
file. Since ProGuard works with Java bytecode, we want to run ProGuard on the class files that are created by the Java compiler, before the build process converts the Java bytecode into Dalvik bytecode. This isn't possible with the regular Eclipse method of creating Android packages (at least, not that I know of), but it's a cinch if you use Ant to build your application. It doesn't take long to create an Ant build script to build your existing Android application. See the instructions on my blog post here. Or, you can just download the sample at the end of this blog. Adding ProGuard to the Ant build script
Download the latest ProGuard distribution. Inside, find the library, and put it in a convenient location in your project directory, such asproguard/
. For example, in the latest version as of this writing (4.5.1 distribution), I copied lib/proguard.jar
from the distribution ZIP file into my source tree as proguard/proguard.jar
. Now, we add the script to the Ant build file, build.xml
. <!-- ================================================= -->
<!-- Obfuscation with ProGuard -->
<!-- ================================================= -->
<property name="proguard-dir" value="proguard"/>
<property name="unoptimized" value="${proguard-dir}/unoptimized.jar"/>
<property name="optimized" value="${proguard-dir}/optimized.jar"/>
<target name="optimize" unless="nooptimize">
<jar basedir="${out.classes.dir}" destfile="${unoptimized}"/>
<java jar="${proguard-dir}/proguard.jar" fork="true" failonerror="true">
<jvmarg value="-Dmaximum.inlined.code.length=16"/>
<arg value="@${proguard-dir}/config.txt"/>
<arg value="-injars ${unoptimized}"/>
<arg value="-outjars ${optimized}"/>
<arg value="-libraryjars ${android.jar}"/>
</java>
<!-- Delete source pre-optimized jar -->
<!--delete file="${unoptimized}"/-->
<!-- Unzip target optimization jar to original output, and delete optimized.jar -->
<delete dir="${out.classes.dir}"/>
<mkdir dir="${out.classes.dir}"/>
<unzip src="${proguard-dir}/optimized.jar" dest="${out.classes.dir}"/>
<!-- Delete optimized jar (now unzipped into bin directory) -->
<delete file="optimized.jar"/>
</target>
optimize
Ant target between the Java compiler and dex compiler, we change the dex target as so:Android 7 and below:
<!-- Converts this project's .class files into .dex files -->
<target name="-dex" depends="compile,optimize">
-post-compile
target, and add this:<target name="-post-compile">
<antcall target="optimize"/>
</target>
Configuring ProGuard
Now we'll tell ProGuard how it can work with our Android application. Create a file calledproguard/config.txt
, which is referenced in the above Ant script. The following is taken from the ProGuard manual, although -libraryjars
, -injars
, and -outjars
is passed in via the Ant build script instead of here. -target 1.6
-optimizationpasses 2
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
# The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle.
-optimizations !code/simplification/arithmetic
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
# Also keep - Enumerations. Keep the special static
# methods that are required in enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-verbose
and -printusage unused.txt
. You may remove these if you don't like the extra output cluttering your build process. Results
Now we're ready! When you runant release
from the command line, you will see the optimizer run. Here is the output from the test project, included below, when the build property config.logging
is true
: >ant release
...
[java] Shrinking...
[java] Printing usage to [blog\obfuscation\proguard\unused.txt]...
[java] Removing unused program classes and class elements...
[java] Original number of program classes: 8
[java] Final number of program classes: 2
-printusage unused.txt
, we can see what was removed from our code: com.androidengineer.obfu.Obfuscation:
private static final java.lang.String TAG
com.androidengineer.obfu.R
com.androidengineer.obfu.R$attr
com.androidengineer.obfu.R$drawable
com.androidengineer.obfu.R$layout
com.androidengineer.obfu.R$string
com.androidengineer.obfu.TestClass:
private static final java.lang.String TAG
proguard/unoptimized.jar
and proguard/optimized.jar
. We can see that it removed many classes which were just placeholders for constants, and it removed the string TAG
variables used by our logging code by replacing the references with the actual string constants. In addition, if we build the application by changing the build property
config.logging
to false
, we get an even further reduction in size. The best part about it is, it removes all of our debugging code.>ant release
...
[java] Original number of program classes: 8
[java] Final number of program classes: 1
TestClass
. Because it is only used when Config.LOGGING
is true
, it is completely removed from the final build during the obfuscation process. So feel free to leave all of the debugging code you want in your source, because it can be removed during the build. Of course, with our simple test project, our results are skewed, because it is not a typical Android application.
proguard/unoptimized.jar
is 4,959 bytes and proguard/optimized.jar
is 646 bytes. But on an application I work with, which has over a thousand classes, I've seen a literal 50% reduction of code size. Well worth the trouble of setting this build up, in my opinion. ClassNotFoundExceptions
There may be some cases where you get aClassNotFoundException
when running your application which has been obfuscated with ProGuard. In this case, you need to edit the config.txt
file to tell ProGuard to keep the class in question. For example, # Keep classes which are not directly referenced by code, but referenced by layout files.
-keep,allowshrinking class com.androidengineer.MyClass
{
*** (...);
}
View
class in an Android layout file, such as MyButton extends Button
, but the class is not referenced in regular code. More information can be found in the ProGuard documentation. Update for Android SDK versions 7 and above
Google updated the Ant scripts in the later SDK versions. They changed the name of a key variable,$[android-jar}
, to ${android.jar}
. This caused the builds to break. The solution is to define them both if they do not exist: <!-- In newer platforms, the build setup tasks were updated to begin using ${android.jar} instead of ${android-jar}. This makes them both compatible. -->
<target name="target-new-vars" unless="android-jar">
<property name="android-jar" value="${android.jar}"/>
</target>
<!-- Be sure to call target-new-vars before anything else. -->
<target name="config" depends="target-new-vars,clean">
The sample project file below has been updated.
Update for Android SDK versions 8
Well, it turns out Google changed the ant build files again. This time, though, they actually made it pretty darn easy. The build.xml file is much smaller this time. They've added a nifty new section:<!-- extension targets. Uncomment the ones where you want to
do custom work in between standard targets -->
<!--
<target name="-pre-build">
</target>
<target name="-pre-compile">
</target>
[This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override
${out.dex.input.absolute.dir}]
<target name="-post-compile">
</target>
-->
-post-compile
Ant target, and add our obfuscation Ant target to it.<target name="-post-compile">
<antcall target="optimize"/>
</target>
Using Google's License Verification Library (LVL)
For those of you using the Google licensing service, License Verification Library, you will want to keep an additional class from being obfuscated in the additional library. Be sure the following is in yourproguard/config.txt
file.-keep class com.android.vending.licensing.ILicensingService
Sample Application
The sample application is a simple Hello World application, but it includes the custom build script and ProGuard library as described in this tutorial. First, you must run "android update project -p .
" from the command line in the project's directory to let the tools set the SDK path in local.properties
. Then you can turn on and off logging by changing the value of config.logging
in build.properties
. Finally, run ant release
to build the application, which will create the obfuscated and signed .apk
file. If you have any trouble, you may want to review the previous blog post about setting up Ant builds.
Project source code - obfuscation.zip (600 Kb)
Build file for Android API level 8 and above:build.xml (4.52 Kb)
261 comments:
«Oldest ‹Older 201 – 261 of 261Download Xtreme Motorbikes Mod Apk
Clash Mini Apk
Venmo Purchase Protection
Facebook Lite App Free Download
Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.
hospital security
condo concierge
security truck
security license brampton
Really good information, well written article. Thanks for sharing an article.
Alignment near me
roadside assistance services
Trailer repair
Trailer repair shop
Very informative blog! I liked it and was very helpful for me. Thanks for sharing. Do share more ideas regularly.
moving services near me
commercial movers near me
house movers ontario
self storage company
I want to thank you for some excellent articles!
It is seldom to find so good and accurate info
on the web. Keep up the great work!
Beauty Salon Near Me
Piercing Near Me
Laser Hair Removal Near Me
Waxing Near Me
Eyelash Lift and Tint Near Me
Microblading Near Me
Permanent Makeup Near Me
Microneedling Near Me
Cryotherapy Near Me
Microdermabrasion Near Me
Waxing Near Me
Thanks for sharing this informative post. We were looking for this type of informative post. We hope you will continue to share similar posts.
AVIATOR JACKET WOMEN
SHEARLING JACKETS
LEATHER BOMBER JACKET
STUDDED LEATHER JACKET WOMEN
What is progurd on Android Engineer
Hey, do you know what is the best mobile editing app for Android? One my friends suggest me to use Kinemaster is the best one.
I was impressed by your writing. Your writing is impressive. I want to write like you.파워볼사이트 I hope you can read my post and let me know what to modify. My writing is in I would like you to visit my blog.
I've been looking for photos and articles on this topic over the past few days due to a school assignment, 우리카지노 and I'm really happy to find a post with the material I was looking for! I bookmark and will come often! Thanks :D
Get a beautiful website for your business today and connect with the best website designer in Meerut. If you are looking for a leading website designing in Meerut then meet Ankita Saxena a leading website designer and seo services provider in Meerut.
She works in a leading company located in Meerut, providing high quality seo services in Meerut and a leading website designing in Meerut with an award of best seo company in Meerut.
Best website designer in Meerut
I really like you and This information is really very helpful. Thank you for sharing.
I will make sure to be reading your blog more. You made a good point Thanks!
if you want to learn UI Development Visit Our Website. https://www.achieversit.com/ui-development-training-course-institute-in-bangalore
This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. John Dutton Jacket
Hi, this is such a great article.
I’ll bookmark your site and come back to read your
other articles!
Cara Print dari Hp
Cara NgePrint lewat Hp
DA PA DR UR
Backlink
Starway is a company with expertise of Design, Engineering, Manufacture, Integration, Installation, Turnkey Execution and After Sales Service / Support in both Photovoltaic and Thermal heating systems, waste to energy, fire management, globally, directly and through its associates.
Starway energy private limited
Starway Energy Meerut
I no uncertainty esteeming each and every bit of it. It is an amazing site and superior to anything normal give. I need to grateful. Marvelous work! Every one of you complete an unfathomable blog, and have some extraordinary substance. Keep doing stunning 메이저사이트순위
Our the purpose is to share the reviews about the latest Jackets,Coats and Vests also share the related Movies,Gaming, Casual,Faux Leather and Leather materials available Rand Al Thor Coat
blog
agecalculator.com
I am someone who works on the web. Sometimes I like to visit overseas sites 메이저안전놀이터 when I have time. Among them, I like the site related to , but your site seems to be optimized for too!! Very good
I love to recommend you Where can crawl Exciting Products latest Jackets, Coats and Vests Click Here Jimmy Hurdstorm Hoodie
Hey friend, it is very well written article, thank you for the valuable and useful information you provide in this post. Keep up the good work! FYI, german shepherd growth chart , How do chips make credit cards more secure, why i am an atheist,Short Paragraph on A Book Fair
DAV CENTENARY SCHOOL is an English Medium School in the Meerut District of Uttar Pradesh.
The school is famous for providing the best quality education and striving students towards excellence.
It has its name always in the list of Top 10 CBSE Schools in Meerut. Currently, it is said to be the best school in Meerut.
DAV CENTENARY SCHOOL MEERUT.
DAV CENTENARY SCHOOL MEERUT.
DAV CENTENARY SCHOOL MEERUT.
I like your blog very much. Thanks for sharing such amazing blogs always. hudson bay coat
We are looking for a lot of data on this item. In the meantime, this is the perfect article I was looking for . Please post a lot about items related to 바카라사이트 !!! I am waiting for your article. And when you are having difficulty writing articles, I think you can get a lot of help by visiting my .
Microsoft Office 365 Product Key with crack are often liberated to prompt all designs of Microsoft Office 365 specifically. Following activation of Microsoft Office 365 applying people discussing keys, you’ve have been supplied no demand any crack or serial key for once again activation. You're also involved https://freeprosoftz.com/microsoft-office-365-product-key/
Best Software development Company in Delhi.
InfotonicsMedia: The Leading https://www.infotonicsmedia.com/software-development-company-in-delhi/ in Delhi.
Software development Company in Faridabad.
Software development Company in Gurgaon.
Contents on this blog is always amazing and informative! Jamb candidates have to use jamb portal to login.
Nice post
Senior school students should check out the WAEC timetable for exam 2022.
read haryanvi status in hindi - ReadAnyThing
haryanvi staus
Our the purpose is to share the reviews about the latest Jackets,Coats and Vests also share the related Movies,Gaming, Casual,Faux Leather and Leather materials available. Jennifer Lopez Parka
Thank you for this wonderful post, great article, keep up the excellent work. Check out our blog Best DU LLB Coaching in Delhi
Any creature can look at the WiFi Password Hacker Online section in the diagram and would like to use it for free. Online Wifi Hacker
Get intelligent suggestions in the Editor Overview pane in Word and let Editor assist you across documents, email, and on the web MS Office 2016 With Crack
Deep Dark Love Quotes quotations area unit simply phrases or quotes concerning deep love with such a splash of romance, tranquilly, and joy thrown certain smart live. True Love Dark Love Quotes
Thanks for such a fantastic blog. Where else could anyone get that kind of info written in such a perfect way? I have a presentation that I am presently writhing on, and I have been on the look out for such great information. 먹튀검증사이트
I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
Amazing content
Manufacturer of Motorcycle clothing
https://rucatisports.com/
https://webjunoon.com/
It's amazing. I want to learn your writing skills. In fact, I also have a website. If you are okay, please visit once and leave your opinion. Thank you. 바카라게임사이트
Nice content, please checkout my website iPourit.in
Or
Visit www.Pourit.in
Youre so right. Im there with you. Your weblog is definitely worth a read if anyone comes throughout it. Im lucky I did because now Ive received a whole new view of this. 먹튀검증사이트
UnoGeeks Offers the best Oracle Fusion Financials Training in the market today. If you want to become Expert Fusion Financials Consultant, Enrol in the
Oracle Fusion Financials Online Training offered by UnoGeeks.
THanks for sharing !
Please do CHeck ma website Factsride.com
Very interesting post and I want more updates from your blog. Thanks for your great efforts...
Separation Before Divorce
Cost of Legal Separation VS Divorce
Small business procurement software
Nice information thanks a lot.
vegetable name
Birds name
This very informative and interesting blog.
Tire repair near me
This very informative and interesting blog.
sell my house fast ontario
This very informative and interesting blog.
web designing company toronto
Thank you for sharing an amazing post. This is a awesome article
Mod Plus Apk
All Apks Mod
Thanks for sharing this amazing and informative post. keep sharing with us.
B3 Men Shearling Aviator Bomber Leather Jackets
i was looking for this content..
Bilastine Tablet 20 mg
Obeticholic Acid Tablets 10 mg
Progesterone Soft Gelatin Capsule
GambleAware provide gamers and their families advice and steerage on gambling. They 점보카지노 provide information and advice to encourage accountable gambling, each to gamers and casino operators, and give assist to those that might have a gambling drawback. If the participant stands, then the banker hits on a complete of 5 or much less. Should the stakes of the punters exceed the quantity for the time being within the financial institution, the banker just isn't liable for the quantity of such excess. In the event of their shedding, the croupier pays the punters in order of rotation, so far as the funds within the financial institution will prolong; beyond this, they haven't any declare.
I have not any word to appreciate this post…..Really i am impressed from this post….
Golden Satta Matka
Milan Matka
Satta Matka Kalyan Chart
Further, outstanding gambling corporations are also investing in offering new platforms and content to enhance the customer expertise out there market}. They make friends with people and claim that they've won cash gambling, and encourage other users to go to mirror sites. David Lee says this advertising is "necessary thing} to success" for on-line gambling operators. We present a number of on-line casino-style games based mostly on Roulette, Blackjack, Video Poker, Table Games and Big Jackpot slots. The thecasinosource.com reasons people offered for the reduction included lack of accessibility (e.g., no reside sports, closed casinos), financial pressures and lack of curiosity. Post-pandemic follow-ups will reveal who returns and doesn't return to previous ranges of gambling involvement.
You need to methods to|learn to} outline the bankroll on your games earlier than you place your first guess on the roulette wheel. And then, want to|you should|you have to} pressure yourself to stay to that quantity — no matter what happens at the desk. My focus is to show out|to indicate} you how to to|tips on how to} maximize your probabilities to win when you play. Not to rip-off you with a bogus system to win cash on roulette on a regular basis} or to show you winning roulette secrets and techniques that don't exist. With a bankroll of €80 and a lower restrict of €1, I place bets of between €5 and €8 on every spin. That's as a result of|as a end result of} 우리카지노 I like to mix the size of the games with my winning odds.
For wonderful colour and large-sized printing, the HP Pagewide XL and DesignJet are powerful and fast machines that are be} expecially catered to produce very good technical documents and graphics design initiatives. Commercial printers are figuring out the growth opportunities in diversification to labels and packaging. During the occasion, HP Indigo may even be showcasing the HP Indigo 6K Digital Press, the spine of the digital label market, with Tower Heaters over 2000 lively worldwide presses. More than 1,400 label converters globally have minimal of|no much less than} one HP Indigo 6K Digital Press.
Thanks for sharing this amazing and informative post. keep sharing with us.
American leather jackets for men
It is simply dishonest to characterize the economic system as doing well. On the economic system, highlighting the final quarter’s decline in GDP just isn't a “falsehood.” Although it is correct that GDP grew in earlier quarters, the characterization that the economic system is nice just isn't. The final quarter is always crucial and predictive, if there may be} any prediction at all. The ongoing inability of the Lions defense to adequately handle velocity operating throughout the field instead of 바카라사이트 vertically urgent them remains the only greatest weak spot on the staff. The Colts uncovered and exploited this in their joint practices in coaching camp and the Lions have not found an answer yet regardless of trying quantity of} different ways. More velocity and consciousness at slot CB, S and LB are sorely needed this offseason.
Post a Comment