Skip to content

Github mirror of "apps/android/wikipedia" - our actual code is hosted with Gerrit (please see https://www.mediawiki.org/wiki/Developer_access for contributing

License

Notifications You must be signed in to change notification settings

bhavikpatel/apps-android-wikipedia

Repository files navigation

See also https://git.wikimedia.org/summary/apps%2Fandroid%2Fjava-mwapi.git

Table of Contents

Steps to Get Up and Developing on a Mac

These instructions should help a Mac owner download the Wikipedia for Android source code and get the latest - sometimes not yet tested - version running in an emulator and on a real Android device. If you don't know anything about how to navigate around a UNIX/Linux/Mac filesystem and edit files with a program like pico, emacs, or vim, these instructions probably won't make any sense. And as noted below, you probably need to understand git in order to ever contribute source code updates to the new app (new release ~first quarter of 2014). And regarding source code, you will need to probably be pretty good at Java or iOS programming, but more ideally the Android-flavored Java used in Android development to really get down to work or play quickly. But anyway, here we go for those who enjoy a fun side project for a good cause...

1. Download the "ADT Bundle for Mac" from https://developer.android.com/sdk/index.html. This includes Eclipse. However, some other developers are currently using IntelliJ IDEA as their primary Android development IDE. Never hurts to have a couple of IDEs for different purposes.

2. Extract the ADT Bundle compressed file you just downloaded, into a folder of its own inside of /Applications/ (e.g., /Applications/adt/).

3. On a Mac, you'll want to update your ~/.bash_profile file to set the $ANDROID_HOME variable to point to the 'sdk' folder contained in the compressed file you just extracted and to update your system path to point at some binaries.

 export ANDROID_HOME=/Applications/adt/sdk
 export PATH=$ANDROID_HOME/tools:$PATH

Now, any time you open a new Terminal, the $ANDROID_HOME variable will be set automatically and you'll be able to run command line tools pertinent to Android software development, such as the tool aptly named "android".

4. Speaking of which, in a new Terminal window, run the following command:

 android sdk

This will load a GUI tool called "Android SDK Manager" for managing the Android-related packages necessary for Android programming.

5. The dependencies among the packages in order to support older and newer versions of Android devices can require some effort. But the following selection set is an okay starting point at first (later on you may need to add more stuff to test on different devices and properly compile the app).

Tools:

  • Android SDK Tools (Rev 22.3)
  • Android SDK Platform-tools (Rev 19.0.1)
  • Android SDK Build-tools (Rev 19.0.1)
  • Android SDK Build-tools (Rev 19)
  • Android SDK Build-tools (Rev 18.1)
Android 4.4 (API 19):
  • SDK Platform Android 4.4.2 (API 19, Rev 2)
  • ARM EABI v7a System Image (API 19, Rev 2)
Android 4.3 (API 18):
  • SDK Platform (API 18, Rev 1)
  • ARM EABI v7a System Image (API 18, Rev 1)
Android 4.2.2 (API 17):
  • SDK Platform (API 17, Rev 2)
Extras:
  • Android Support Repository (Rev 3)
  • Android Support Library (Rev 19)
So, using Android SDK Manager, install that stuff, and once you're satisfied that everything has been downloaded and installed, feel free to close the Android SDK Manager.

6. Download and install Maven from http://maven.apache.org/download.cgi. Follow the instructions in the section "Unix-based Operating Systems (Linux, Solaris and Mac OS X)". Note again how the instructions talk about setting environment variables. Assuming, you created /usr/local/apache-maven and planted a folder in there called, for example, "maven-3.1.1", you would want to add the following to your ~/.bash_profile:

 export M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
 export M2=$M2_HOME/bin
 export MAVEN_OPTS="-Xms256m -Xmx512m"
 export PATH=$M2:$PATH

Maven relies upon Java. If in the Terminal you can type the command "java -version" and you yet you don't have a $JAVA_HOME environment variable, Maven will probably Just Work on Mac, so you don't necessarily need to add and export JAVA_HOME in ~/.bash_profile like the instructions suggest. If, on the other hand you don't have Java, download and install the latest version of the Java SDK in the 1.6 series (or if unsupported, maybe 1.7, ...) and ensure you can get "java -version" to work.

Now, in a new Terminal window, type the following command to ensure Maven is working.

 mvn --version

7. In the parent directory of your programming projects, run the following commands:

 git clone https://git.wikimedia.org/git/apps/android/wikipedia.git

If you've never used git, you will need to search the web on how to add git to the system from Apple Xcode, and then study on how to use git (look for material on https://mediawiki.org for git convention as practiced by MediaWiki programmers).

Assuming the git clone operation worked, you will have a new folder representing the freshly cloned repository, "wikipedia".

8. It is recommended to rename the folder for the "wikipedia" repository to ensure you know which OS it's for (there's an iOS app by the name of "wikipedia", too, so it's good to have different folder names at the root of the repos).

 mv wikipedia/ android-wikipedia/

9. Install IntelliJ IDEA Community Edition from http://www.jetbrains.com/idea/download/index.html.

10. Open IntelliJ IDEA, and choose to Import Project. Select the "android-wikipedia" folder and click OK.

In the Import Project dialog box, select the "Import project from external model" radio button and then choose "Maven" from the list of options. Click Next.

The defaults on the next screen need one tweak: check the checkbox labeled "Import Maven Projects automatically". Click Next.

On the next screen, there should be one checkbox checked for the project to import. Leave it as is, and then click Next.

In the next screen, on the lefthand pane, highlight the "Android API 19 Platform", ensure that Build _target of 4.4 and and Java SDK of 1.6 are set before clicking Next. If you didn't see the "Android API 19 Platform" option, you will probably need to (1) click the "+" symbol and choose "JDK" on this dialog box to first add the base SDK '1.6' value; IntelliJ kind of just figures out where the Java SDK is based for you, so don't be surprised if it has dug several folders deep...then (2) click the "+" symbol again choose "Android SDK", then navigate to the "sdk" folder of the ADT folder.

On the next screen accept the default of "wikipedia-parent" and click Finish.

11. Now wait - it can take a while! - IntelliJ IDEA will try to download project dependencies with its Maven integration. Sometimes you need to cd into the android-wikimedia folder do a mvn install to jumpstart the process, alternating back and forth to figure out the source of dependency problems and to get things downloaded.

A message may pop up that says, "Error when importing module '~apklib-android.support_compatibility-v7-appcompat_19.0.0': Cannot find src directory in <project></project>/wikipedia/gen-external-apklibs/android.support_compatibility-v7-appcompat_19.0.0" - this message may safely be ignored.

12. Assuming all dependencies were downloaded cleanly, in IntelliJ IDEA go to Build > Make Project.

13. If everything goes well, the project will have compiled neatly. There may be a few warnings, but no fatal errors.

Now, it's time to either run the app on an Android device or in an emulator. The emulator is slow due to being a full stack implementation. So most people seem to prefer to push apps to real Android devices.

14. To setup a configuration for a real Android device, first, on your Android device, go into Settings. Depending on your version of Android OS, you may need to take a different approach, but usually you can go to "About <phone/table></phone/table>" and tap repeatedly on the "Build number" cell until it tells you that you've put the device in developer mode. Now that developer mode is turned on, from the Settings app go into "Developer options" and turn on USB debugging (you may want to turn this feature off later on when you don't need it). Now, connect your Android device to your Mac. You'll be prompted with a message about allowing USB debugging for a particular RSA key fingerprint. Click OK to that.

Next, in IntelliJ

  • A. In IntelliJ, go to Run > Edit Configurations.
  • B. Click the "+" symbol and choose Android Application.
  • C. Choose "Wikipedia" for the Module.
  • D. Change the _target Device from Emulator to USB Device.
  • E. Type a descriptive name in the Name field such as "Nexus 4 Physical Device".
  • F. Click OK
Now up in the top right part of IntelliJ you should see a green colored play button. Also if you go to the Run menu you should see an option to, for example "Run Nexus 4 Physical Device". Use either option to pop the app onto your device and run it! The Wikipedia apps uses an internet connection, so you'll want to probably turn on internet access before launching the app via the play button or run menu.

One of IntelliJ's standout features is debugging. If you want to do that, you just need to click the Debug (green bug) button. To set breakpoints in your code, as with other IDEs, click in the gutter to the left of the source code in the IDE and notice that a little red circle is added. For example, if you set a breakpoint in the first line of public CommunicationBridge(final WebView webView, final String baseURL) in CommunicationBridge.java -

 this.webView = webView;

- you'll get a glimpse into what actually happens the moment after tapping on an article title from search results. With the debugger, you can step through the code one line at a time, jump over methods, manipulate variables to see what would happen, and so on. Refer to online documentation to learn more about how the debugger works.

15. Now, if you wanted to use the emulator, first you'd want to run the following command in Terminal:

 android avd

This will launch the Android Virtual Device Manager application where you can create different virtual machines with specs representative of devices in the wild. Again, the emulator is slow, but it's nice to be able to see how things work out on different screen sizes when you don't have lots of devices handy. To create a device, just go to the Device Definitions tab of Android Virtual Device Manager, click on one of the profiles, and then click "Create AVD". And in the ensuing dialog box set the _target to, for example, Android 4.4 - API Level 19, then click OK. You'll now see the virtual machine in the Android Virtual Devices tab.

Note: you can also go to the Tools > Android > AVD Manager in IntelliJ to get to the same interface.

Now that you have an emulator virtual machine ready, you can go to Run > Edit Configurations in IntelliJ again, click the '+' symbol, choose Android Application, set the Module to 'wikipedia', and ensure Emulator is chosen, choosing the preferred emulator from the list of eligible emulators, setting a descriptive Name, then clicking OK. Then click the Play button or use the Run menu to get it started. A window will ensue for you to verify the configuration, to which you click OK. Then wait a while for everything to fire up and enjoy the emulator.

16. Logcat Configuration

After starting the project you'll likely notice a torrent of messages in the logcat window, and so it can help to setup a filter to cut down on those messages.

  • At the top of the window, click on the "No Filters" drop-down list and select "Edit Filter Configuration"
  • Change the name to something more meaningful ("android-wikipedia" for example)
  • In the text field "by Package Name" enter "org.wikipedia"
  • Because the log level can be changed on the main interface, it may be helpful to leave the level set to "Verbose"
  • Select "OK"
17. Checkstyle Configuration to see Checkstyle errors as you type

In the IntelliJ preferences (settings), go to Plugins and install the Checkstyle-IDEA inspection plugin. Then go to the Checkstyle setting and add a new configuration file: browse to the local file checkstyle.xml. Make sure you check the new configuration file so our checkstyle inspections are enabled and show up as IntelliJ errors in the code editor. Also check "Scan test classes" above.

18. Enjoy.

19. Help make it better!

Updating bundled JavaScript

Portions of JavaScript code run inside the WebView component that displays articles. This code is prepackaged using a [Grunt-js](http://gruntjs.com/getting-started), which must be re-run every time the master .js files are edited before building.

Preparing:

First, install the Grunt CLI tool:

 npm install -g grunt-cli

Install dependencies for packaging:

 cd www
 npm install

Building:

 cd www
 grunt

This will produce output files under wikipedia/assets which will be included in the .apk.

You can also have grunt run continuously, watching the effected files for updates and running the build tasks automatically. This might be useful.

 cd www
 grunt watch
 ... update files ...

Updating icons from SVG

Many of our icons are maintained as SVG originals, rasterized to PNG at the various output resolutions via a script. This rasterization is not part of the main build process, so needs to be re-run when adding new icons.

Setup

Install sh python module:

 sudo easy_install sh

Ensure you have librsvg and the 'rsvg-convert' command:

  • On Ubuntu, run "sudo apt-get install librsvg2-bin"
  • On Mac OS X using Homebrew, run "brew install librsvg"
You also need to have ImageMagick (for flipping of icons):

  • On Mac OS X using Homebrew, run "brew install imagemagick"

Convert

Run:

 python scripts/convert-icons.py

Original files from icon-svgs/*/*.svg are rendered and copied into the res/ subdirectories. Note that they are not automatically added to git!

Updating generated static data files

Setup

sudo pip install unicodecsv sudo pip install jinja2

Run

cd scripts python make-templates.py mv *.java ../wikipedia/src/main/java/org/wikipedia/staticdata/

About

Github mirror of "apps/android/wikipedia" - our actual code is hosted with Gerrit (please see https://www.mediawiki.org/wiki/Developer_access for contributing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 84.1%
  • JavaScript 10.0%
  • CSS 4.4%
  • Python 1.4%
  • Shell 0.1%
  NODES
COMMUNITY 2
Idea 8
idea 8
INTERN 2
Note 4
Project 16
USERS 1
Verify 1