Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 | |
| 2 How to set up and run the sample app as an Android Studio project. | |
| 3 | |
| 4 Linux (Android Studio version 0.8.11 beta) | |
| 5 ===== | |
| 6 (1) Launch Android Studio | |
| 7 | |
| 8 (2) Choose "Import project" | |
| 9 - navigate to chromium/src/components/cronet/android/sample | |
| 10 - pick a destination for it | |
| 11 | |
| 12 (3) Copy in the 'jar' files | |
| 13 (a) directly under the "app" directory of your project | |
| 14 create a "libs" directory. Use a shell command if you like, | |
| 15 or use "File|New|Directory" from the menu. But note that | |
| 16 you only get "Directory" as an option if you are in | |
| 17 "Project" view, not "Android" view. "Project" models | |
| 18 the local machine's filesystem, but Android is a virtual | |
| 19 layout of files corresponding to the deployed hierarchy. | |
| 20 That is to say, do step (b) before step (a) if you're inclined. | |
| 21 (b) toggle the view from "Android" to "Project" | |
| 22 in the selection list above the file hierarchy. | |
| 23 Otherwise you won't see "libs" | |
| 24 (c) Copy 'cronet.jar' and 'cronet_stub.jar' to "libs" | |
| 25 | |
| 26 (4) Inform the IDE about the Jar files | |
| 27 (a) Shift+click both files | |
| 28 (b) Right mouse | |
| 29 (c) Pick "Add as Library" | |
| 30 (d) Confirm "OK" at the "Add to module" dialog | |
| 31 | |
| 32 (5) Copy in the '.so' file | |
| 33 (a) under "app/src/main" create a directory named "jniLibs" | |
| 34 (b) copy armeabi and ameabi-v7a into jniLibs, which should | |
| 35 contain only subdirectories, not directly a '.so' file | |
| 36 (c) the IDE will automatically know about these | |
| 37 | |
| 38 (6) Click "Run" | |
| 39 | |
| 40 If the project doesn't build, there are two typical problems: | |
| 41 1) make sure that you have the correct 'cronet.jar'. | |
| 42 There is one that is part of the Chromium build which | |
| 43 does not include org.chromium.base (and so will be missing PathUtil, | |
| 44 at least) and one that is part of the cronet build. | |
| 45 | |
| 46 2) If you have vast swaths of red text (errors) in the edit window | |
| 47 for CronetSampleActivity, you should confirm that the requisite | |
| 48 jar files are present in 'build.gradle'. There are at least 2 | |
| 49 files which are named that. Look in them both. | |
| 50 You should observe the following lines: | |
| 51 | |
| 52 dependencies { | |
| 53 compile file('libs/cronet.jar') | |
| 54 compile file('libs/cornet_stub.jar') | |
| 55 } | |
| 56 "compile" as used here means to package those jars into the apk, | |
| 57 and not to make those files. | |
| 58 | |
| 59 If absent, the lines may be added by hand to the gradle file | |
| 60 which corresponds to the module named "app", and not the project | |
| 61 s a whole. You might have to press a "Sync" button in the IDE | |
| 62 which tells it to re-scan the 'build.gradle' files. | |
| 63 | |
| 64 If the project builds but doesn't run, verify that the '.so' files | |
| 65 re present in your Android package (which is just a jar file in disguise): | |
| 66 % jar tf build/outputs/apk/app-debug.apk | |
| 67 AndroidManifest.xml | |
| 68 res/layout/cronet_sample_activity.xml | |
| 69 resource.arsc | |
| 70 classes.dex | |
| 71 lib/armeabi/libcronet.so | |
| 72 lib/armeabi-v7/libcronet.so | |
| 73 META-INF | |
| 74 etc | |
| 75 | |
| 76 If the '.so' files are not present, it is likely that Android Studio | |
| 77 misinterpreted the containing folder as "ordinary" source code, | |
| 78 which, due to lack of any special directive pertaining to it, failed | |
| 79 to be copied to the apk. One thing to check for is the spelling | |
| 80 of "jniLibs" - it must literally be that, with a capital "L" or | |
| 81 it won't work. This is a bit of magic that allows users without | |
| 82 the NDK (Native Development Kit) to deploy '.so' files. | |
| 83 [With the NDK, things are different because in that case you have to | |
| 84 produce the '.so' files, and create build rules to do so, | |
| 85 so the setup is naturally more flexible to begin with.] | |
| 86 As a visual cue that the folder has been recognized as special, | |
| 87 its icon should match that of the "res" (resources) folder | |
| 88 which resembles a tabbed manila folder with some extra cross-hatches | |
| 89 on the front, and not the icon of the "java" folder. | |
| 90 The marking on the icon signifies that its contents land on the | |
| 91 the target device. But to keep things interesting, the icon is | |
| 92 distinct visually only in "Android" view, not "Project" view. | |
| 93 | |
| 94 MacOS (studio version 1.0.1) | |
|
dougk
2015/02/05 22:42:36
oh forgot this "Android Studio"
| |
| 95 ===== | |
| 96 (0) you might have to set a magic environment variable as follows: | |
| 97 export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk | |
| 98 | |
| 99 This has to do with differences between the JDK that the studio runs in | |
| 100 as distinct from the JDK that the studio understands to be present on | |
| 101 the target machine. | |
| 102 | |
| 103 (1) Launch Android Studio, | |
| 104 which can be achieved from the command line with | |
| 105 % open '/Applications/Android Studio.app' | |
| 106 | |
| 107 (2) Choose "Import Non-Android Studio Project" | |
| 108 (a) Navigate to the path containing "sample" | |
| 109 (b) Pick a place to put it, and choose "Finish" | |
| 110 I'll use "~/my_example" | |
| 111 | |
| 112 (3) If you are comfortable using shell commands to create directories, | |
| 113 you may proceed to step (3) for Linux above. | |
| 114 Otherwise, if you prefer to create directories from the UI, | |
| 115 the following approach will work: | |
| 116 | |
| 117 (4) Choose "File -> New -> Folder -> Assets Folder" | |
| 118 Check "Change Folder Location" and delete the entire | |
| 119 pathname that was there. Change it to 'libs' | |
| 120 which is conventional for pre-built jar files. | |
| 121 | |
| 122 (5) Copy and paste the two pre-built '.jar' files into 'assets' | |
| 123 When you do this, it will say that the destination is | |
| 124 "app/libs". This is right. If you prefer to see | |
| 125 the file hierarchy as it really exists, you can change | |
| 126 the dropdown above the tree view from "android view" | |
| 127 to "project view". Or just keep in mind that assets = libs | |
| 128 at this level of the hierarchy. | |
| 129 | |
| 130 (6) Select both jar files that you added (Shift+click) | |
| 131 and pull up the menu for them (Ctrl+click). | |
| 132 Select "Add as library" | |
| 133 | |
| 134 (7) Choose "File -> New -> Folder -> JNI Folder" | |
| 135 Choose "Change Folder Location" | |
| 136 and change the name to "src/main/jniLibs" | |
| 137 The reason you have to change the name is that Gradle has an automatic | |
| 138 rule that tries to build binary libraries in src/main/jni. | |
| 139 But you don't want to trigger that rule because it will complains if | |
| 140 you don't have the Native Development Kit. | |
| 141 The magic name of "jniLibs" tells Android Studio that you only | |
| 142 want to depend on the libraries therein. | |
| 143 | |
| 144 ---- | |
| 145 | |
| 146 Internal note: | |
| 147 | |
| 148 Ideally the two .jar files and one .so file could be delivered as one .aar | |
| 149 (Android Archive) file, but Studio will try to pull aar files from a maven | |
| 150 repository without some workarounds that are about as much trouble | |
| 151 as adding in three separate files. | |
| 152 See https://code.google.com/p/android/issues/detail?id=55863 | |
| 153 | |
| 154 Additionally, it is unclear how to automate the creation of a '.aar' file | |
| 155 outside of Android Studio and Gradle. If the entire workflow were controlled | |
| 156 by Gradle, it would be one thing; but presently the cronet jars are | |
| 157 produced as artifacts of the Chromium build which uses Ninja. | |
| OLD | NEW |