Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 Adblock Plus Library for Android | 1 Adblock Plus Library for Android |
2 ======================== | 2 ======================== |
Felix Dahlke
2017/02/23 12:53:59
Nit: Please prolong this to match the title above.
| |
3 | 3 |
4 An Android library project that provides an opportunity to use Adblock Plus core | 4 An Android library project, tests and demo application for AdblockWebView widget . |
anton
2016/12/02 06:10:03
Now using like in https://hg.adblockplus.org/adblo
| |
5 functionality in Java/Android. | 5 |
6 | 6 ## Updating the dependencies |
7 Updating the dependencies | 7 |
8 ------------------------- | 8 Adblock Plus for Android has dependencies that aren't in this repository. |
9 | |
10 Adblock Plus Library for Android has dependencies that aren't in this repository . | |
11 To update those, call: | 9 To update those, call: |
12 | 10 |
13 ./ensure_dependencies.py | 11 ./ensure_dependencies.py |
14 | 12 |
15 ## Library | 13 ## Library |
16 | 14 |
17 Building with Ant | 15 An Android library that provides the core functionality of Adblock Plus. |
18 ------------------ | 16 You can find it in the 'libadblockplus-android' directory. |
19 | 17 |
20 ### Requirements | 18 ### Building with Ant |
19 | |
20 #### Requirements | |
21 | 21 |
22 * [The Android SDK](http://developer.android.com/sdk) | 22 * [The Android SDK](http://developer.android.com/sdk) |
23 * [The Android NDK](https://developer.android.com/tools/sdk/ndk) | 23 * [The Android NDK](https://developer.android.com/tools/sdk/ndk) |
24 * [Ant](http://ant.apache.org) | 24 * [Ant](http://ant.apache.org) |
25 | 25 |
26 ### Building | 26 #### Building |
27 | 27 |
28 In the 'libadblockplus-android' directory create the file _local.properties_ and set | 28 In the 'libadblockplus-android' directory create the file _local.properties_ and set |
29 _sdk.dir_ and _ndk.dir_ to where you installed it, e.g.: | 29 _sdk.dir_ and _ndk.dir_ to where you installed it, e.g.: |
30 | 30 |
31 sdk.dir = /some/where/sdk | 31 sdk.dir = /some/where/sdk |
32 ndk.dir = /some/where/ndk | 32 ndk.dir = /some/where/ndk |
33 | 33 |
34 Then run: | 34 Then run: |
35 | 35 |
36 ant debug | 36 ant debug |
37 | 37 |
38 Building with Maven | 38 ### Building with Maven |
39 ------------------- | 39 |
40 #### Requirements | |
41 | |
42 All 'Building with Ant' requirements and additional requirements: | |
43 | |
44 * [Maven](https://maven.apache.org) | |
45 | |
46 #### Building | |
47 | |
48 Go to android sdk directory '/platforms/android-21' and run: | |
49 | |
50 mvn install:install-file -Dfile=./android.jar -DgroupId=com.google.android - DartifactId=android | |
51 -Dversion=5.0 -Dpackaging=jar -DgeneratePom=true | |
52 | |
53 Set environment variable ANDROID_HOME to your Android SDK directory or pass it i n command-line (below). | |
54 In the root directory run: | |
55 | |
56 » mvn clean install [-Dandroid.sdk.path=/some/where/sdk] | |
57 | |
58 This will generate *.aar library artifacts in the 'libadblockplus-android/target ', | |
59 'libadblockplus-android-settings/target', 'libadblockplus-android-webview/target ' directories | |
60 and *.apk in the 'libadblockplus-android-webviewapp/target' directory. | |
61 | |
62 ### Building with Gradle/Android Studio | |
63 | |
64 #### Requirements | |
65 | |
66 * [The Android SDK](http://developer.android.com/sdk) | |
67 * Android SDK Build tools 24.0.1 | |
68 * [The Android NDK](https://developer.android.com/tools/sdk/ndk) | |
69 | |
70 Edit 'buildToolsVersion' in 'build.gradle' files if necessary. | |
71 | |
72 #### Building from command-line | |
73 | |
74 In the project root directory create the file _local.properties_ and set | |
75 _sdk.dir_ and _ndk.dir_ to where you installed it, e.g.: | |
76 | |
77 sdk.dir = /some/where/sdk | |
78 ndk.dir = /some/where/ndk | |
79 | |
80 In the project root directory run: | |
81 | |
82 ./gradlew assembleDebug | |
83 | |
84 This will generate *.aar library artifact in the 'libadblockplus-android/build/o utputs/aar/' directory. | |
85 | |
86 ## Library tests | |
87 | |
88 Android tests for the library. | |
89 You can find them in the 'libadblockplus-android-tests' directory. | |
40 | 90 |
41 ### Requirements | 91 ### Requirements |
42 | 92 |
43 All 'Building with Ant' requirements and additional requirements: | |
44 | |
45 * [Maven](https://maven.apache.org) | |
46 | |
47 ### Building | |
48 | |
49 Set environment variable ANDROID_HOME to your Android SDK directory or pass it i n command-line (below). | |
50 In the 'libadblockplus-android' directory run: | |
51 | |
52 mvn clean install [-Dandroid.sdk.path=/some/where/sdk] | |
53 | |
54 This will generate *.aar library artifact in the 'target' directory. | |
55 | |
56 ## Library tests | |
57 | |
58 ### Requirements | |
59 | |
60 Make sure _Library_ requirements are present. | 93 Make sure _Library_ requirements are present. |
61 | 94 |
62 ### Building | 95 ### Building with Ant |
63 | 96 |
64 Set ANDROID_HOME environment variable to your Android SDK directory. | 97 Set ANDROID_HOME environment variable to your Android SDK directory. |
65 | 98 |
66 In the 'libadblockplus-android-tests' run: | 99 In the 'libadblockplus-android-tests' directory run: |
67 | 100 |
68 ant instrument | 101 ant instrument |
69 | 102 |
70 ### Testing | 103 ### Testing with Ant |
71 | 104 |
72 1. Connect an Android device or start the Android Emulator. | 105 1. Connect an Android device or start the Android Emulator. |
73 2. In the 'libadblockplus-android-tests' directory run: | 106 2. In the 'libadblockplus-android-tests' directory run: |
74 | 107 |
75 ant instrument install test | 108 ant instrument install test |
76 | 109 |
77 to build instrumentation tests app and perform testing or run: | 110 to build instrumentation tests app and perform testing or run: |
78 | 111 |
79 ant test | 112 ant test |
80 | 113 |
81 to run installed instrumentation tests app. | 114 to run installed instrumentation tests app. |
82 | 115 |
83 To run specific **test** run: | 116 To run specific **test** run: |
84 | 117 |
85 ant testOnly -DtestClass=full.test.class.name | 118 ant testOnly -DtestClass=full.test.class.name |
86 | 119 |
87 For example: | 120 For example: |
88 | 121 |
89 ant testOnly -DtestClass=org.adblockplus.libadblockplus.tests.NotificationTe st | 122 ant testOnly -DtestClass=org.adblockplus.libadblockplus.tests.NotificationTe st |
90 | 123 |
91 To run specific **test method** run: | 124 To run specific **test method** run: |
92 | 125 |
93 ant testOnly -DtestClass=full.test.class.name#testMethod | 126 ant testOnly -DtestClass=full.test.class.name#testMethod |
94 | 127 |
95 For example: | 128 For example: |
96 | 129 |
97 ant testOnly -DtestClass=org.adblockplus.libadblockplus.tests.NotificationTe st#testAddNotification | 130 ant testOnly -DtestClass=org.adblockplus.libadblockplus.tests.NotificationTe st#testAddNotification |
131 | |
132 ### Building with Gradle/Android Studio | |
133 | |
134 Make sure you've created the _local.properties_ file to build the library (see a bove). | |
135 In the project root directory run: | |
136 | |
137 ./gradlew assembleDebugAndroidTest | |
138 | |
139 This will generate *.apk in the 'libadblockplus-android-tests/build/outputs/apk/ ' directory. | |
140 | |
141 ### Testing with Gradle/Android Studio | |
142 | |
143 You can select test class/method and click 'Run ..Test'. The library and test ap p will be | |
144 compiled, installed to emulator/device and launched automatically. | |
145 | |
146 ## Settings | |
147 | |
148 An Android library that provides a configuration interface for Adblock Plus. | |
149 You can find it in the 'libadblockplus-android-settings' directory: | |
150 * GeneralSettingsFragment - main fragment | |
151 * WhitelistedDomainsSettingsFragment - whitelisted domains fragment | |
152 | |
153 ### Usage | |
154 | |
155 Create `AdblockEngine` instance with factory methods and `AdblockSettingsStorage ` instance. | |
156 You can use `SharedPrefsStorage` implementation to store settings in `SharedPref erences`. | |
157 Or you can use AdblockHelper: | |
158 | |
159 AdblockHelper.get().init(this, true, AdblockHelper.PREFERENCE_NAME); | |
160 | |
161 Implement the following interfaces in your settings activity: | |
162 | |
163 * `BaseSettingsFragment.Provider` | |
164 * `GeneralSettingsFragment.Listener` | |
165 * `WhitelistedDomainsSettingsFragment.Listener` | |
166 | |
167 and return created instance or AdblockHelper instances: | |
168 | |
169 AdblockHelper.get().getEngine(); // engine | |
170 AdblockHelper.get().getStorage(); // storage | |
171 | |
172 Retain Adblock instance in activity `onCreate` in synchronous mode (it may take few seconds): | |
173 | |
174 AdblockHelper.get().retain(false); | |
175 | |
176 or in asynchronous mode (without current thread lock): | |
177 | |
178 AdblockHelper.get().retain(true); | |
179 | |
180 Invoke `waitforReady` every time you need AdblockEngine instance if retained in asynchronous mode: | |
181 | |
182 AdblockHelper.get().waitForReady(); | |
183 | |
184 Release Adblock instance in activity `onDestroy`: | |
185 | |
186 AdblockHelper.get().release(); | |
187 | |
188 Insert `GeneralSettingsFragment` fragment instance in runtime to start showing s ettings UI. | |
189 | |
190 ### Building | |
191 | |
192 #### Building with Ant | |
193 | |
194 In the 'libadblockplus-android-settings' directory create the file _local.proper ties_ and set | |
195 _sdk.dir_ to where you installed it, e.g.: | |
196 | |
197 sdk.dir = /some/where/sdk | |
198 | |
199 Then run: | |
200 | |
201 ant debug | |
202 | |
203 | |
204 #### Building with Gradle | |
205 | |
206 In the project root directory run: | |
207 | |
208 ./gradlew assemble | |
209 | |
210 This will generate *.aar in the 'libadblockplus-android-settings/build/outputs/a ar' directory. | |
211 | |
212 ## WebView | |
213 | |
214 An Android library that provides a WebView component with Adblock Plus integrate d. | |
215 You can find it in the 'libadblockplus-android-webview' directory. | |
216 | |
217 `AdblockWebView` class provides built-in ad blocking | |
218 (both resource loading filtering and element hiding) and inherits from Android | |
219 ['WebView'](https://developer.android.com/reference/android/webkit/WebView.html) . | |
220 | |
221 ### Usage | |
222 | |
223 In layout XML: | |
224 | |
225 <org.adblockplus.libadblockplus.android.webview.AdblockWebView | |
226 android:id="@+id/main_webview" | |
227 android:layout_width="match_parent" | |
228 android:layout_height="match_parent"/> | |
229 | |
230 In java source code: | |
231 | |
232 AdblockWebView webView = (AdblockWebView) findViewById(R.id.main_webview); | |
233 | |
234 Use `setAdblockEnabled(boolean adblockEnabled)` to enable/disable adblocking. | |
235 | |
236 Use `setDebugMode(boolean debugMode)` to turn debug log output (Android log and JS console) on/off. | |
237 | |
238 Use `setAllowDrawDelay(int allowDrawDelay)` to set custom delay to start render webpage after 'DOMContentLoaded' event is fired. | |
239 | |
240 Use `setAdblockEngine(AdblockEngine adblockEngine)` to use external adblock engi ne. | |
241 If adblock engine is not set, it's created by AdblockWebView instance automatica lly. | |
242 | |
243 Use `dispose(Runnable disposeFinished)` to release resources (**required**). | |
244 Note it can be invoked from background thread. | |
245 | |
246 ### Building | |
247 | |
248 #### Building with Ant | |
249 | |
250 In the 'libadblockplus-android-webview' directory create the file _local.propert ies_ and set | |
251 _sdk.dir_ to where you installed it, e.g.: | |
252 | |
253 sdk.dir = /some/where/sdk | |
254 | |
255 Then run: | |
256 | |
257 ant debug | |
258 | |
259 | |
260 #### Building with Gradle | |
261 | |
262 In the project root directory run: | |
263 | |
264 ./gradlew assemble | |
265 | |
266 This will generate *.aar in the 'libadblockplus-android-webview/build/outputs/aa r' directory. | |
267 | |
268 ## WebView Application | |
269 | |
270 An Android application that demonstrates how to use AdblockWebView. | |
271 You can find it in the 'libadblockplus-android-webviewapp' directory. | |
272 | |
273 ### Building | |
274 | |
275 Make sure _Library_ requirements are present. | |
276 | |
277 #### Building with Ant | |
278 | |
279 In the 'libadblockplus-android-webviewapp' directory create the file _local.prop erties_ and set | |
280 _sdk.dir_ to where you installed it, e.g.: | |
281 | |
282 sdk.dir = /some/where/sdk | |
283 | |
284 Then run: | |
285 | |
286 ant debug | |
287 | |
288 This will generate *.apk in the 'libadblockplus-android-webviewapp/bin/' directo ry. | |
289 | |
290 #### Building with Gradle | |
291 | |
292 In the project root directory run: | |
293 | |
294 ./gradlew assemble | |
295 | |
296 This will generate *.apk in the 'libadblockplus-android-webviewapp/build/outputs /apk/' directory. | |
LEFT | RIGHT |