<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Life of Coding</title>
 <link href="http://lifeOfCoding.com/atom.xml" rel="self"/>
 <link href="http://lifeOfCoding.com/"/>
 <updated>2015-08-27T13:25:09+00:00</updated>
 <id>http://lifeOfCoding.com</id>
 <author>
   <name>Wesley Lin</name>
   <email>westlinkin@gmail.com</email>
 </author>

 
 <entry>
   <title>Why I prefer AppCode over Xcode</title>
   <link href="http://lifeOfCoding.com/2015/08/07/Why-I-prefer-AppCode-over-Xcode/"/>
   <updated>2015-08-07T00:00:00+00:00</updated>
   <id>http://lifeOfCoding.com/2015/08/07/Why-I-prefer-AppCode-over-Xcode</id>
   <content type="html">&lt;p&gt;For the past four months, I&amp;#39;ve been learning iOS development. Basically I just read a &lt;a href=&quot;http://www.amazon.com/Beginning-iPhone-Development-Exploring-iOS-ebook/dp/B00M4FC7O6/ref=mt_kindle?_encoding=UTF8&amp;amp;me=&quot;&gt;book&lt;/a&gt;, and then started writing code. I haven&amp;#39;t started &lt;code&gt;Swift&lt;/code&gt; language yet, for most iOS open-source libraries are written in &lt;code&gt;Objective-C&lt;/code&gt;. And I think I won&amp;#39;t start using &lt;code&gt;Swift&lt;/code&gt; in another one or two years.&lt;/p&gt;

&lt;p&gt;As an Android developer, I am used to &lt;code&gt;Android Studio&lt;/code&gt;, which is a fantastic IDE for coding. For those Android developers who havn&amp;#39;t using &lt;code&gt;Android Studio&lt;/code&gt;yet, I strongly recommend you try it. &lt;/p&gt;

&lt;p&gt;When I started using &lt;code&gt;Xcode&lt;/code&gt; for iOS development, I am very confused.&lt;/p&gt;

&lt;h3&gt;What is wrong with Xcode&lt;/h3&gt;

&lt;h5&gt;I accidentally close projects all the time.&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;cmd + w&lt;/code&gt; is a common shortcut for close a tab or window on OSX. If you&amp;#39;re using &lt;code&gt;Safari&lt;/code&gt; or &lt;code&gt;Chrome&lt;/code&gt;, you know what I mean. If there are more than one tab in your brower when you use &lt;code&gt;cmd + w&lt;/code&gt;, it close the focused tab. If there is no tab left, it close the window. It&amp;#39;s quite easy to understand, right? But NOOOO, &lt;code&gt;Xcode&lt;/code&gt; doesn&amp;#39;t behave like that. If you use &lt;code&gt;cmd + w&lt;/code&gt;, it close the whole project.&lt;/p&gt;

&lt;h5&gt;Delete a whole line? NO!&lt;/h5&gt;

&lt;p&gt;You can&amp;#39;t use &lt;code&gt;cmd + delete&lt;/code&gt; to delete a whole line, which is also a common shortcut on OSX. Yes, you can delete a whole line of code using &lt;code&gt;cmd + delete&lt;/code&gt;, but if there is just an extra line and you wanna to delete it? &lt;code&gt;cmd + delete&lt;/code&gt; will delete the line and delete half the line above it.&lt;/p&gt;

&lt;h5&gt;Code completion sucks&lt;/h5&gt;

&lt;p&gt;If you wanna use a certain method in a &lt;code&gt;NSObject&lt;/code&gt;, which has a word &lt;code&gt;index&lt;/code&gt; in it, but you can&amp;#39;t remenber the whole name of the method, what will you do? Look up the document or source code to get the exact name or the first letter of the method? Because &lt;code&gt;Xcode&lt;/code&gt; can only auto-complete code from the beginning. For example, if you type in &lt;code&gt;[Object index&lt;/code&gt;, the IDE won&amp;#39;t tell you all the methods related to &lt;code&gt;index&lt;/code&gt; keyword, it can only tell you the methods started with &lt;code&gt;index&lt;/code&gt;. This really makes writing code slower.&lt;/p&gt;

&lt;h5&gt;NO Auto-import&lt;/h5&gt;

&lt;p&gt;Why not? Even &lt;code&gt;Eclipse&lt;/code&gt; has this feature a long long time ago. I can&amp;#39;t stand that when I am writing a method/function, the IDE tells me:&amp;quot; Oh, I can&amp;#39;t recognize this. Oh, you can&amp;#39;t use that&amp;quot;.&lt;/p&gt;

&lt;h5&gt;Can you really see the Log?&lt;/h5&gt;

&lt;p&gt;The font and line spacing of the Log console is a disaster. The text is bold and line spacing is way too small. So the log just looks like a black block. I can&amp;#39;t really distinguish one log from another.&lt;/p&gt;

&lt;h5&gt;CocoaPods&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;CocoaPods&lt;/code&gt; is a dependency manager for iOS development, like &lt;code&gt;gradle&lt;/code&gt; or &lt;code&gt;maven&lt;/code&gt; for Android and Java. To use &lt;code&gt;CocoaPods&lt;/code&gt; in your project, you can follow the steps on the &lt;a href=&quot;https://cocoapods.org/&quot;&gt;CocoaPods website&lt;/a&gt;. This is not convenient enough! Becuase you need to use the terminal, which &lt;code&gt;Xcode&lt;/code&gt; do not provide a shortcut to open and relocate to the project folder. You will have to open a terminal, then go to the project folder, or go to the project folder in finder and open a terminal there. Finally you need to run a command line to install the dependencies. Why all the trouble? &lt;code&gt;AppCode&lt;/code&gt; can do all that for you, all you need to do is editing the &lt;code&gt;Podfile&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;AppCode is better&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;AppCode&lt;/code&gt; fixes all the complaints I have about &lt;code&gt;Xcode&lt;/code&gt;, plus I can use all the keymap I am already familiar with in &lt;code&gt;Android Studio&lt;/code&gt;. Just export the keymap settings in &lt;code&gt;Android Studio&lt;/code&gt; and import it in &lt;code&gt;AppCode&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can find out many other better feature of &lt;code&gt;AppCode&lt;/code&gt; on the &lt;a href=&quot;https://www.jetbrains.com/objc/features/&quot;&gt;official website&lt;/a&gt;. I am sure there are a lot to explore. You can find some tricks and tips on the &lt;a href=&quot;http://blog.jetbrains.com/objc/&quot;&gt;AppCode Blog&lt;/a&gt;. This IDE truely makes my life a lot easier.&lt;/p&gt;

&lt;h3&gt;Flaws in AppCode&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;AppCode&lt;/code&gt; is not perfect, though. When it comes to edit &lt;code&gt;xib&lt;/code&gt; or &lt;code&gt;storyboard&lt;/code&gt; file, it is crappy. And &lt;code&gt;AppCode&lt;/code&gt; sure cannot submit apps to the AppStore. It&amp;#39;s also not that good when editing the project settings.&lt;/p&gt;

&lt;p&gt;Now my workflow of a new project is this: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create new project using &lt;code&gt;Xcode&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Config &lt;code&gt;CocoaPods&lt;/code&gt; in &lt;code&gt;AppCode&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Edit &lt;code&gt;xib&lt;/code&gt; and &lt;code&gt;storyboard&lt;/code&gt; in &lt;code&gt;Xcode&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Write &lt;code&gt;Objective-C&lt;/code&gt; code in &lt;code&gt;AppCode&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Config project in &lt;code&gt;Xcode&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Submit to beta test or AppStore in &lt;code&gt;Xcode&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Because &lt;code&gt;AppCode&lt;/code&gt; can sync code and files instantly with &lt;code&gt;Xcode&lt;/code&gt;, you don&amp;#39;t need to worry about conflicts when editing the same project/file using two IDEs.&lt;/p&gt;

&lt;h3&gt;Others&lt;/h3&gt;

&lt;p&gt;I don&amp;#39;t mean starting an argument about which IDE is better. It&amp;#39;s just, to me, &lt;code&gt;Xcode&lt;/code&gt; is not good enough. I can be more efficient and focused when using &lt;code&gt;AppCode&lt;/code&gt;, that&amp;#39;s what really matters.&lt;/p&gt;

&lt;p&gt;If you are always an &lt;code&gt;Xcode&lt;/code&gt; user, you can try a &lt;a href=&quot;https://www.jetbrains.com/objc/download/&quot;&gt;30-day trial&lt;/a&gt; of &lt;code&gt;AppCode&lt;/code&gt;, I mean, it doesn&amp;#39;t hurt, does it? If you don&amp;#39;t like, leave it there, delete it, do whatever you want with it. But if you like it, you will find out it really is an productivity tool. After all, IDE should make coder efficiency, right?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Change Android studio Logcat text color to Eclipse style</title>
   <link href="http://lifeOfCoding.com/2015/04/22/Change-Android-studio-Logcat-text-color-to-Eclipse-style/"/>
   <updated>2015-04-22T00:00:00+00:00</updated>
   <id>http://lifeOfCoding.com/2015/04/22/Change-Android-studio-Logcat-text-color-to-Eclipse-style</id>
   <content type="html">&lt;p&gt;Android studio is better than Eclipse with ADT in almost every way. I&amp;#39;ve been using it for almost a year now. However, Logcat is an exception. Only &lt;code&gt;Assert&lt;/code&gt;, &lt;code&gt;Error&lt;/code&gt; and &lt;code&gt;Warn&lt;/code&gt; log level&amp;#39;s text has different color, which makes it very dificult to distinguish between &lt;code&gt;Info&lt;/code&gt;, &lt;code&gt;Debug&lt;/code&gt; and &lt;code&gt;Verbose&lt;/code&gt; log level. And I believe these three log levels are mostly common used by app developers (including me of course).&lt;/p&gt;

&lt;h3&gt;Locate Logcat Settings&lt;/h3&gt;

&lt;p&gt;Open Android Studio preferences (press &lt;code&gt;cmd + ,&lt;/code&gt; if on OSX), you can find Android Logcat settings in &lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;Editor ==&amp;gt; Colors &amp;amp; Fonts ==&amp;gt; Android Logcat
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Click &lt;code&gt;Save As...&lt;/code&gt; button to save the current scheme, name it.&lt;/p&gt;

&lt;p&gt;Uncheck the &lt;code&gt;Use inherited attributes&lt;/code&gt; checkbox, in order to change the text style.&lt;/p&gt;

&lt;h3&gt;Find Eclipse Logcat style&lt;/h3&gt;

&lt;p&gt;You can find the Eclipse Logcat color setting in the follow foottrace in preferences:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;Android ==&amp;gt; LogCat ==&amp;gt; Colors
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In case you have already deleted Eclipse or didn&amp;#39;t bother to open it, here is the RGB color of each log levels:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;Verbose:  000000
Debug: 00007F
Info: 027F00
Warn: FF7F00
Error: FF0000
Assert: FF0000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;Others&lt;/h3&gt;

&lt;p&gt;I use the Android studio default &lt;code&gt;Assert&lt;/code&gt; color to make it different from &lt;code&gt;Error&lt;/code&gt; log level.&lt;/p&gt;

&lt;p&gt;I use the Android studio default theme, not &lt;code&gt;Darcular&lt;/code&gt;, so the Eclipse logcat style works for me. If you are using the dark &lt;code&gt;Darcular&lt;/code&gt; theme, there is already &lt;a href=&quot;https://plus.google.com/+CyrilMottier/posts/Q6cZdf57cj7&quot;&gt;a good color set&lt;/a&gt; for it.&lt;/p&gt;

&lt;p&gt;Finnaly, here is the colorful logcat:
&lt;img src=&quot;/images/android-studio-logcat.png&quot; alt=&quot;img&quot;&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Execute JavaScript in Android without WebView</title>
   <link href="http://lifeOfCoding.com/2015/04/05/Execute-JavaScript-in-Android-without-WebView/"/>
   <updated>2015-04-05T00:00:00+00:00</updated>
   <id>http://lifeOfCoding.com/2015/04/05/Execute-JavaScript-in-Android-without-WebView</id>
   <content type="html">&lt;p&gt;For some reason, I need to execute JavaScript code in an Android project. Because the JavaScript code was running in a background thread(in &lt;code&gt;doInBackground&lt;/code&gt; part in an &lt;a href=&quot;http://developer.android.com/reference/android/os/AsyncTask.html&quot;&gt;&lt;code&gt;AsyncTask&lt;/code&gt;&lt;/a&gt;), I don&amp;#39;t want to use &lt;code&gt;WebView&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;Why not WebView&lt;/h3&gt;

&lt;p&gt;First of all, WebView is heavy. WebView is slow, especially in a large/huge project. Plus, you need to add a lot of WebView related settings to just execute one code snippet. It&amp;#39;s just simply not worth it.&lt;/p&gt;

&lt;p&gt;Secondly, WebView is UI related. A WebView should be created in UI thread. Sure, you can create it in UI thread, load JavaScript code in a background thread, then pass the result back to UI thread. It&amp;#39;s workable, but it&amp;#39;s not safe.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you call methods on WebView from any thread other than your app&amp;#39;s UI thread, it can cause unexpected results. [&lt;a href=&quot;https://developer.android.com/guide/webapps/migrating.html#Threads&quot;&gt;source&lt;/a&gt;]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Last but not least, WebView is fragmented. After Android 4.4(API level 19), Android is using WebView baseed on &lt;a href=&quot;http://www.chromium.org/Home&quot;&gt;Chromuim&lt;/a&gt;. Although this is toally a good thing, the WebView in Android 4.3 and below suffers the old version. You should code two version of WebView related code to just make it work. A lot of code should be re-write according to &lt;a href=&quot;https://developer.android.com/guide/webapps/migrating.html&quot;&gt;this article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Luckily, the good people in Mozilla make a project called &lt;code&gt;Rhino&lt;/code&gt;. It is typically embedded into Java applications to provide scripting to end users.&lt;/p&gt;

&lt;h3&gt;How to use Rhino&lt;/h3&gt;

&lt;p&gt;Rhino is a open source project, you can get the source code using this command:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;git clone https://github.com/mozilla/rhino.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or fork their project on &lt;a href=&quot;https://github.com/mozilla/rhino&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Of course, you don&amp;#39;t have to get the source code. If you want to use it in your Android project. &lt;a href=&quot;https://github.com/mozilla/rhino/releases/download/Rhino1_7R5_RELEASE/rhino1_7R5.zip&quot;&gt;Download Rhino&lt;/a&gt; first, unzip it, put the &lt;code&gt;js.jar&lt;/code&gt; file under &lt;code&gt;libs&lt;/code&gt; folder. It is very small, so you don&amp;#39;t need to worry your apk file will be ridiculously large because of this one external jar.&lt;/p&gt;

&lt;p&gt;Here is some simple code to execute JavaScript code.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;javaScriptParam&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Every Rhino VM begins with the enter()&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// This Context is not Android&amp;#39;s Context&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Context&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rhino&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;enter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Turn off optimization to make Rhino Android compatible&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;rhino&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setOptimizationLevel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Scriptable&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scope&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rhino&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;initStandardObjects&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Note the forth argument is 1, which means the JavaScript source has&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// been compressed to only one line using something like YUI&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rhino&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;evaluateString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scope&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;javaScriptCode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;JavaScript&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Get the functionName defined in JavaScriptCode&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scope&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;functionNameInJavaScriptCode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scope&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;instanceof&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Function&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jsFunction&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Function&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// Call the function with params&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jsResult&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jsFunction&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rhino&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scope&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scope&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Parse the jsResult object to a String&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;jsResult&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see, it is quite easy. You can dig up more in &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Rhino_documentation&quot;&gt;Rhino document&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Proguard &amp;amp; Obfuscation&lt;/h3&gt;

&lt;p&gt;You can set up Rhino&amp;#39;s proguard setting by adding this following line into your &lt;code&gt;proguard-android.txt&lt;/code&gt; file.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;-keep class org.mozilla.javascript.** { *; }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;When you run the &lt;code&gt;assembleRelease&lt;/code&gt; task, with &lt;code&gt;minifyEnabled true&lt;/code&gt; of course, you still can see a lot of warning like these:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;Warning: org.mozilla.javascript.tools.shell.JSConsole: can&amp;#39;t find referenced class javax.swing.JMenu
Warning: org.mozilla.javascript.tools.shell.JSConsole: can&amp;#39;t find referenced class javax.swing.JMenu
Warning: org.mozilla.javascript.tools.shell.JSConsole: can&amp;#39;t find referenced class javax.swing.JMenu
Warning: org.mozilla.javascript.tools.shell.JSConsole: can&amp;#39;t find referenced class javax.swing.ButtonGroup
Warning: org.mozilla.javascript.tools.shell.JSConsole: can&amp;#39;t find referenced class javax.swing.JScrollPane
Warning: org.mozilla.javascript.tools.shell.JSConsole: can&amp;#39;t find referenced class java.awt.event.ActionEvent
Warning: org.mozilla.javascript.tools.shell.JSConsole: can&amp;#39;t find referenced class java.awt.event.ActionEvent
Warning: org.mozilla.javascript.tools.shell.JSConsole$1: can&amp;#39;t find referenced class javax.swing.filechooser.FileFilter
Warning: org.mozilla.javascript.tools.shell.JSConsole$2: can&amp;#39;t find referenced class java.awt.event.WindowAdapter
Warning: org.mozilla.javascript.tools.shell.JSConsole$2: can&amp;#39;t find referenced class java.awt.event.WindowEvent
Warning: org.mozilla.javascript.tools.shell.JSConsole$2: can&amp;#39;t find referenced class java.awt.event.WindowEvent
Warning: org.mozilla.javascript.xml.impl.xmlbeans.LogicalEquality: can&amp;#39;t find referenced class org.apache.xmlbeans.XmlCursor
Warning: org.mozilla.javascript.xml.impl.xmlbeans.LogicalEquality: can&amp;#39;t find referenced class org.apache.xmlbeans.XmlCursor
Warning: org.mozilla.javascript.xml.impl.xmlbeans.LogicalEquality: can&amp;#39;t find referenced class org.apache.xmlbeans.XmlCursor
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Luckily, evan with these warnings, the app runs fine. You can ignore them(that&amp;#39;s what I do), or adding this line inot your &lt;code&gt;proguard-android.txt&lt;/code&gt; file.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;-dontwarn org.mozilla.javascript.**
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>How to increase Android Studio memory limit in Mac</title>
   <link href="http://lifeOfCoding.com/2015/01/19/How-to-increase-Android-studio-memory-limit-in-Mac/"/>
   <updated>2015-01-19T00:00:00+00:00</updated>
   <id>http://lifeOfCoding.com/2015/01/19/How-to-increase-Android-studio-memory-limit-in-Mac</id>
   <content type="html">&lt;p&gt;The &lt;a href=&quot;http://tools.android.com/tech-docs/configuration&quot;&gt;technical doc&lt;/a&gt; of configuring Android Studio on the Android Tools Project site is out dated. So you can not increase memory limit by configuring the &lt;code&gt;studio.vmoptions&lt;/code&gt; file under &lt;code&gt;~/Library/Preferences/AndroidStudio/&lt;/code&gt; folder. Actually, in my case, there is no &lt;code&gt;studio.vmoptions&lt;/code&gt; or &lt;code&gt;idea.properties&lt;/code&gt; file like the doc said.&lt;/p&gt;

&lt;h3&gt;Locate the configuration file&lt;/h3&gt;

&lt;p&gt;If you are using &lt;code&gt;Terminal&lt;/code&gt;, run command&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;open -e /Applications/Android\ Studio.app/Contents/bin/studio.vmoptions
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or, you can also open &lt;code&gt;Applications&lt;/code&gt; folder in Finder, press &lt;code&gt;ctrl&lt;/code&gt; then click or just right-click on Android Studio, choose &lt;code&gt;Show Package Contents&lt;/code&gt;, you can find &lt;code&gt;studio.vmoptions&lt;/code&gt; file under &lt;code&gt;Contents/bin&lt;/code&gt; folder.&lt;/p&gt;

&lt;h3&gt;Config your settings&lt;/h3&gt;

&lt;p&gt;You can just edit your &lt;code&gt;studio.vmoptions&lt;/code&gt; file, increasing your &lt;code&gt;Xms&lt;/code&gt; and &lt;code&gt;Xmx&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Xmx&lt;/code&gt; specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), while &lt;code&gt;Xms&lt;/code&gt; specifies the initial memory allocation pool. Your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory.&lt;/p&gt;

&lt;p&gt;This is my configuration:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;-Xms128m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=200m
-XX:+UseCompressedOops
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Once you make the changes, don&amp;#39;t forget to &lt;strong&gt;RESTART&lt;/strong&gt; Android Studio.&lt;/p&gt;

&lt;h3&gt;Other&lt;/h3&gt;

&lt;p&gt;If you want to fall back to default values, here it is:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;-Xms128m
-Xmx750m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=96m
-XX:+UseCompressedOops
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or you can &lt;a href=&quot;http://tools.android.com/tech-docs/configuration&quot;&gt;download&lt;/a&gt; it from the Android Tools Project Site.&lt;/p&gt;

&lt;p&gt;I think increasing the memory limit in IntelliJ IDEA is the same, I didn&amp;#39;t check it though.&lt;/p&gt;
</content>
 </entry>
 

</feed>
