aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 9b00655c8b683a1c8d02588423328b6919026e13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# WordPress for Android #

[![Build Status](https://travis-ci.org/wordpress-mobile/WordPress-Android.svg?branch=develop)](https://travis-ci.org/wordpress-mobile/WordPress-Android)

If you're just looking to install WordPress for Android, you can find
it on [Google Play][1]. If you're a developer wanting to contribute,
read on.

## Build Instructions ##

The [gradle build system][2] will fetch all dependencies and generate
files you need to build the project. You first need to generate the
local.properties (replace YOUR_SDK_DIR with your actual android SDK directory)
file and create the gradle.properties file. The easiest way is to copy
our example:

    $ echo "sdk.dir=YOUR_SDK_DIR" > local.properties
    $ cp ./WordPress/gradle.properties-example ./WordPress/gradle.properties

Note: this is the default `./WordPress/gradle.properties` file. If you
want to use WordPress.com functions (login to a WordPress.com account,
access the Reader and Stats for example), you'll have to get a WordPress.com
OAuth2 ID and secret. Please read the
[OAuth2 Authentication](#oauth2-authentication) section.

The previous command creates a `libs/` directory and clones all dependencies needed
by the main WordPress for Android project. You can now build, install and
test the project:

    $ ./gradlew assembleVanillaDebug # assemble the debug .apk
    $ ./gradlew installVanillaDebug  # install the debug .apk if you have an
                                     # emulator or an Android device connected
    $ ./gradlew cAT                  # assemble, install and run unit tests

You can use [Android Studio][3] by importing the project as a Gradle project.

### Additional Build Instructions for Windows ###

The [visual editor][10] uses a linux-style symlink for its [assets folder][11],
which has to be converted to a Windows symlink.

From git bash, inside the project root:

    $ rm libs/editor/WordPressEditor/src/main/assets
    $ git ls-files --deleted -z | git update-index --assume-unchanged -z --stdin

Then, from a Windows command prompt:

    mklink /D [PROJECT_ROOT]\libs\editor\WordPressEditor\src\main\assets %PROJECT_ROOT%\libs\editor\libs\editor-common\assets

Finally, update `[PROJECT_ROOT]\.git\info\exclude` to ignore the symlink locally:

    # editor assets symlink
    libs/editor/WordPressEditor/src/main/assets

## Directory structure ##

    |-- libs                    # dependencies used to build debug variants
    |-- tools                   # script collection
    `-- WordPress
        |-- build.gradle        # main build script
        |-- gradle.properties   # properties imported by the build script
        `-- src                 # android specific Java code
            |-- androidTest     # test assets, resources and code
            |-- main            #
            |   |-- assets      # main project assets
            |   |-- java        # main project java code
            |   `-- res         # main project resources
            |-- vanilla         # vanilla variant specific manifest
            `-- wasabi          # wasabi variant specific resources and manifest

## OAuth2 Authentication ##

In order to use WordPress.com functions you will need a client ID and
a client secret key. These details will be used to authenticate your
application and verify that the API calls being made are valid. You can
create an application or view details for your existing applications with
our [WordPress.com applications manager][5].

When creating your application, you should select "Native client" for the
application type. The applications manager currently requires a "redirect URL",
but this isn't used for mobile apps. Just use "https://localhost".

Once you've created your application in the [applications manager][5], you'll
need to edit the `./WordPress/gradle.properties` file and change the
`WP.OAUTH.APP.ID` and `WP.OAUTH.APP.SECRET` fields. Then you can compile and
run the app on a device or an emulator and try to login with a WordPress.com
account.

Read more about [OAuth2][6] and the [WordPress.com REST endpoint][7].

## How we work ##

You can read more about [Code Style Guidelines](CODESTYLE.md) we adopted, and
how we're organizing branches in our repository in the
[Contribution Guide](CONTRIBUTING.md).

## Need help to build or hack? ##

Say hello on our [Slack][4] channel: `#mobile`.

## Alternative Build Instructions ##

WordPress-Android can be compiled with [Buck][8], an alternative to Gradle,
that makes the build process much faster. You first need to fetch the
dependencies by doing:

    $ buck fetch wpandroid

This command will fetch all dependencies (`.aar` and `.jar`) needed to build
the project. Then you can run buck to build the apk:

    $ buck build wpandroid

You can build, install and run the project if you have a device or an emulator
connected by running the following:

    $ buck install --run wpandroid

It's recommended to install [watchman][9] to take advantage of the Buck
daemon: `buckd`.

## FAQ ##

* Q: I can't build/test/package the project because of a `PermGen space` error.
* A: Create a `build.properties` file in the project root directory with the following: `org.gradle.jvmargs=-XX:MaxPermSize=1024m`.

## License ##

WordPress for Android is an Open Source project covered by the
[GNU General Public License version 2](LICENSE.md). Note: code
in the `libs/` directory comes from external libraries, which might
be covered by a different license compatible with the GPLv2.

[1]: https://play.google.com/store/apps/details?id=org.wordpress.android
[2]: http://tools.android.com/tech-docs/new-build-system/user-guide
[3]: http://developer.android.com/sdk/installing/studio.html
[4]: https://make.wordpress.org/chat/
[5]: https://developer.wordpress.com/apps/
[6]: https://developer.wordpress.com/docs/oauth2/
[7]: https://developer.wordpress.com/docs/api/
[8]: https://facebook.github.io/buck
[9]: https://facebook.github.io/watchman/docs/install.html
[10]: https://github.com/wordpress-mobile/WordPress-Editor-Android
[11]: https://github.com/wordpress-mobile/WordPress-Android/blob/develop/libs/editor/WordPressEditor/src/main/assets