{"id":374,"date":"2014-10-17T08:00:33","date_gmt":"2014-10-17T06:00:33","guid":{"rendered":"http:\/\/blogs.igalia.com\/eocanha\/?p=374"},"modified":"2014-10-17T08:00:33","modified_gmt":"2014-10-17T06:00:33","slug":"hacking-on-chromium-for-android-from-eclipse-part-3","status":"publish","type":"post","link":"https:\/\/eocanha.org\/blog\/2014\/10\/17\/hacking-on-chromium-for-android-from-eclipse-part-3\/","title":{"rendered":"Hacking on Chromium for Android from Eclipse (part 3)"},"content":{"rendered":"<p>In the previous posts we learnt how to code and debug Chromium for Android C++ code from Eclipse. In this post I&#8217;m going to explain how\u00a0to open the ChromeShell Java code, so that you will be able to hack on it like you would in a normal Android app project. Remember, you will need to\u00a0<a href=\"http:\/\/developer.android.com\/sdk\/installing\/installing-adt.html\">install the ADT plugin in Eclipse\u00a0<\/a>\u00a0and the full featured <strong>adb<\/strong> which comes with\u00a0the\u00a0<a href=\"http:\/\/developer.android.com\/sdk\/index.html#download\">standalone SDK from the official page<\/a>.\u00a0<strong>Don&#8217;t<\/strong> try to reuse the android sdk in &#8220;third_party\/android_tools\/sdk&#8221;.<\/p>\n<p><strong>Creating the Java project in Eclipse<\/strong><\/p>\n<p>Follow these instructions to create the Java project for ChromeShell (for instance):<\/p>\n<ul>\n<li>File, New, Project&#8230;, Android, Android project from existing code<\/li>\n<li>Choose &#8220;src\/chrome\/android\/shell\/java&#8221; as project root, because there&#8217;s where the AndroidManifest.xml is. Don&#8217;t copy anything to the workspace.<\/li>\n<li>The project will have a lot of unmet package dependencies. You have to manually import some jars:\n<ul>\n<li>Right click on the project, Properties, Java build path, Libraries, Add external Jars&#8230;<\/li>\n<li>Then browse to &#8220;src\/out\/Debug\/lib.java&#8221; (assuming a debug build) and import these jars (use CTRL+click for multiple selection in the file chooser):\n<ul>\n<li>base_java.jar, chrome_java.jar, content_java.jar, dom_distiller_core_java.jar, guava_javalib.jar,<\/li>\n<li>jsr_305_javalib.jar, net_java.jar, printing_java.jar, sync_java.jar, ui_java.jar, web_contents_delegate_android.jar<\/li>\n<\/ul>\n<\/li>\n<li>If you keep having problems, go to &#8220;lib.java&#8221;, run this script and find in which jar is the class you&#8217;re missing:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre style=\"padding-left: 90px\">for i in *.jar; do echo \"--- $i ---------------------\"; unzip -l $i; done | most<\/pre>\n<ul>\n<li>The generated resources directory &#8220;gen&#8221; produced by Eclipse is going to lack a lot of stuff.\n<ul>\n<li>It&#8217;s better to make it point to the &#8220;right&#8221; gen directory used by the native build scripts.<\/li>\n<li>Delete the &#8220;gen&#8221; directory in &#8220;src\/chrome\/android\/shell\/java&#8221; and make a symbolic link:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre style=\"padding-left: 90px\">ln -s ..\/..\/..\/..\/out\/Debug\/chrome_shell_apk\/gen .<\/pre>\n<ul>\n<ul>\n<li>If you ever &#8220;clean project&#8221; by mistake, delete the chrome_shell_apk\/gen directory and regenerate it using the standard ninja build command<\/li>\n<\/ul>\n<li>The same for the &#8220;res&#8221; directory. From &#8220;src\/chrome\/android\/shell\/java&#8221;, do this (and ignore the errors):<\/li>\n<\/ul>\n<pre style=\"padding-left: 60px\">cp -sr $PWD\/..\/res .\/\ncp -sr $PWD\/..\/..\/java\/res .\/<\/pre>\n<ul>\n<li>I haven&#8217;t been able to solve the problem of integrating all the string definitions. A lot of string related errors will appear in files under &#8220;res&#8221;.\u00a0By the moment, just ignore those errors.<\/li>\n<li>Remember to use a fresh standalone sdk. Install support for Android 4.4.2. Also, you will probably need to modify the project properties to match the same 4.4.2 version you have support for.<\/li>\n<\/ul>\n<p>And that&#8217;s all. Now you can use all the Java code indexing features of Eclipse. By the moment, you still need to build and install to the device using the command line recipe, though:<\/p>\n<pre> ninja -C out\/Debug chrome_shell_apk\n build\/android\/adb_install_apk.py --apk ChromeShell.apk --debug<\/pre>\n<p><strong>Debugging Java code<\/strong><\/p>\n<p>To debug the Java side of the app running in the device, follow the same approach that you would if you had a normal Java Android app:<\/p>\n<ul>\n<li>Launch the ChromeShell app manually from the device.<\/li>\n<li>In Eclipse, use the DDMS perspective to locate the org.chromium.chrome.shell process. Select it in the Devices panel and connect the debugger using the &#8220;light green bug&#8221; icon (not to be mistaken with the normal debug icon available from the other perspectives).<\/li>\n<li>Change to the Debug perspective and set breakpoints as usual.<\/li>\n<\/ul>\n<p>Enjoy!<\/p>\n<p><a href=\"\/blog\/wp-content\/uploads\/2014\/10\/chromium_android_eclipse_java1.png\"><img loading=\"lazy\" class=\"alignnone size-medium wp-image-377\" alt=\"chromium_android_eclipse_java\" src=\"\/blog\/wp-content\/uploads\/2014\/10\/chromium_android_eclipse_java1-300x167.png\" width=\"300\" height=\"167\" srcset=\"https:\/\/eocanha.org\/blog\/wp-content\/uploads\/2014\/10\/chromium_android_eclipse_java1-300x167.png 300w, https:\/\/eocanha.org\/blog\/wp-content\/uploads\/2014\/10\/chromium_android_eclipse_java1-1024x573.png 1024w, https:\/\/eocanha.org\/blog\/wp-content\/uploads\/2014\/10\/chromium_android_eclipse_java1-672x372.png 672w, https:\/\/eocanha.org\/blog\/wp-content\/uploads\/2014\/10\/chromium_android_eclipse_java1-1038x576.png 1038w, https:\/\/eocanha.org\/blog\/wp-content\/uploads\/2014\/10\/chromium_android_eclipse_java1.png 1670w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous posts we learnt how to code and debug Chromium for Android C++ code from Eclipse. In this post I&#8217;m going to explain how\u00a0to open the ChromeShell Java code, so that you will be able to hack on it like you would in a normal Android app project. Remember, you will need to\u00a0install &hellip; <a href=\"https:\/\/eocanha.org\/blog\/2014\/10\/17\/hacking-on-chromium-for-android-from-eclipse-part-3\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Hacking on Chromium for Android from Eclipse (part 3)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,9,2,7],"tags":[],"_links":{"self":[{"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/posts\/374"}],"collection":[{"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/comments?post=374"}],"version-history":[{"count":0,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/posts\/374\/revisions"}],"wp:attachment":[{"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/media?parent=374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/categories?post=374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/tags?post=374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}