Skip to content

Commit

Permalink
Makefile and documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Feb 5, 2016
1 parent 5813f21 commit e3c9e61
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 81 deletions.
136 changes: 87 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,37 @@ S3_BUCKET ?= lantern

DOCKER_IMAGE_TAG := lantern-builder

S3_BUCKET ?= lantern
ANDROID_S3_BUCKET ?= lantern-android
ANDROID_BUILD_DIR := src/github.com/getlantern/lantern-mobile/app/build/outputs/apk
LANTERN_DEBUG_APK := lantern-debug.apk

ANDROID_LIB_PKG := github.com/getlantern/lantern
ANDROID_LIB := liblantern.aar

ANDROID_SDK_DIR := MobileSDK
ANDROID_SDK_LIBS := $(ANDROID_SDK_DIR)/sdk/libs/
ANDROID_SDK_ANDROID_LIB := $(ANDROID_SDK_LIBS)/$(ANDROID_LIB)
ANDROID_SDK := $(ANDROID_SDK_DIR)/sdk/build/outputs/aar/sdk-debug.aar

ANDROID_TESTBED_DIR := LanternMobileTestbed
ANDROID_TESTBED_LIBS := $(ANDROID_TESTBED_DIR)/app/libs/
ANDROID_TESTBED_ANDROID_LIB := $(ANDROID_TESTBED_LIBS)/$(ANDROID_LIB)
ANDROID_TESTBED_ANDROID_SDK := $(ANDROID_TESTBED_LIBS)/sdk-debug.aar
ANDROID_TESTBED := $(ANDROID_TESTBED_DIR)/app/build/outputs/apk/app-debug.apk

LANTERN_MOBILE_DIR := src/github.com/getlantern/lantern-mobile
LANTERN_MOBILE_LIBS := $(LANTERN_MOBILE_DIR)/app/libs
LANTERN_MOBILE_PKG := github.com/getlantern/lantern
LANTERN_MOBILE_LIBRARY := liblantern.aar
MOBILE_TESTBED := LanternMobileTestbed
MOBILE_TESTBED_LIBS := $(MOBILE_TESTBED)/app/libs
MOBILE_SDK := MobileSDK
MOBILE_SDK_LIBS := $(MOBILE_SDK)/sdk/libs
DOCKER_MOBILE_IMAGE_TAG := lantern-mobile-builder
LOGGLY_TOKEN_MOBILE := d730c074-1f0a-415d-8d71-1ebf1d8bd736

FIRETWEET_MAIN_DIR ?= ../firetweet/firetweet/src/main/
TUN2SOCKS := $(LANTERN_MOBILE_DIR)/libs/armeabi-v7a/libtun2socks.so
LANTERN_MOBILE_TUN2SOCKS := $(LANTERN_MOBILE_LIBS)/armeabi-v7a/libtun2socks.so
LANTERN_MOBILE_ANDROID_LIB := $(LANTERN_MOBILE_LIBS)/$(ANDROID_LIB)
LANTERN_MOBILE_ANDROID_SDK := $(LANTERN_MOBILE_LIBS)/sdk-debug.aar
LANTERN_MOBILE := $(LANTERN_MOBILE_DIR)/app/build/outputs/apk/lantern-debug.apk

LANTERN_YAML := lantern.yaml
LANTERN_YAML_PATH := installer-resources/lantern.yaml

.PHONY: packages clean docker
.PHONY: packages clean docker tun2socks android-lib android-sdk android-testbed android-debug android-install

define build-tags
BUILD_TAGS="" && \
Expand Down Expand Up @@ -138,7 +152,6 @@ define fpm-debian-build =
endef

all: binaries
android: tun2socks android-lib android-sdk android-debug android-install android-run
android-dist: genconfig android

# This is to be called within the docker image.
Expand Down Expand Up @@ -247,13 +260,6 @@ docker: system-checks
cp Dockerfile $$DOCKER_CONTEXT && \
docker build -t $(DOCKER_IMAGE_TAG) $$DOCKER_CONTEXT;

docker-mobile:
@$(call docker-up) && \
DOCKER_CONTEXT=.$(DOCKER_MOBILE_IMAGE_TAG)-context && \
mkdir -p $$DOCKER_CONTEXT && \
cp $(LANTERN_MOBILE_DIR)/Dockerfile $$DOCKER_CONTEXT && \
docker build -t $(DOCKER_MOBILE_IMAGE_TAG) $$DOCKER_CONTEXT

update-dist:
UPDATE_DIST=true make genassets

Expand Down Expand Up @@ -507,47 +513,70 @@ genconfig:
source setenv.bash && \
(cd src/github.com/getlantern/flashlight/genconfig && ./genconfig.bash)

android-lib:
@source setenv.bash && \
$(ANDROID_LIB):
source setenv.bash && \
go install golang.org/x/mobile/cmd/gomobile && \
gomobile init && \
$(call build-tags) && \
gomobile bind -target=android -tags='headless' -o=$(LANTERN_MOBILE_LIBRARY) -ldflags="$(LDFLAGS) $$EXTRA_LDFLAGS" $(LANTERN_MOBILE_PKG) && \
mkdir -p $(MOBILE_TESTBED_LIBS) && cp -f $(LANTERN_MOBILE_LIBRARY) $(MOBILE_TESTBED_LIBS) && \
mkdir -p $(MOBILE_SDK_LIBS) && cp -f $(LANTERN_MOBILE_LIBRARY) $(MOBILE_SDK_LIBS) && \
mkdir -p $(LANTERN_MOBILE_LIBS) && cp -f $(LANTERN_MOBILE_LIBRARY) $(LANTERN_MOBILE_LIBS)
gomobile bind -target=android -tags='headless' -o=$(ANDROID_LIB) -ldflags="$(LDFLAGS) $$EXTRA_LDFLAGS" $(ANDROID_LIB_PKG)

android-sdk: android-lib
(cd $(MOBILE_SDK) && gradle assembleDebug) && \
cp $(MOBILE_SDK)/sdk/build/outputs/aar/sdk-debug.aar $(MOBILE_TESTBED_LIBS) && \
cp $(MOBILE_SDK)/sdk/build/outputs/aar/sdk-debug.aar $(LANTERN_MOBILE_LIBS)
android-lib: $(ANDROID_LIB)

android-debug:
cd $(LANTERN_MOBILE_DIR)/app
gradle -b $(LANTERN_MOBILE_DIR)/app/build.gradle \
$(ANDROID_SDK_ANDROID_LIB): $(ANDROID_LIB)
mkdir -p $(ANDROID_SDK_LIBS) && \
cp $(ANDROID_LIB) $(ANDROID_SDK_ANDROID_LIB)

$(ANDROID_SDK): $(ANDROID_SDK_ANDROID_LIB)
(cd $(ANDROID_SDK_DIR) && gradle assembleDebug)

android-sdk: $(ANDROID_SDK)

$(ANDROID_TESTBED_ANDROID_LIB): $(ANDROID_LIB)
mkdir -p $(ANDROID_TESTBED_LIBS) && \
cp $(ANDROID_LIB) $(ANDROID_TESTBED_ANDROID_LIB)

$(ANDROID_TESTBED_ANDROID_SDK): $(ANDROID_SDK)
mkdir -p $(ANDROID_TESTBED_LIBS) && \
cp $(ANDROID_SDK) $(ANDROID_TESTBED_ANDROID_SDK)

$(ANDROID_TESTBED): $(ANDROID_TESTBED_ANDROID_LIB) $(ANDROID_TESTBED_ANDROID_SDK)
cd $(ANDROID_TESTBED_DIR)/app
gradle -b $(ANDROID_TESTBED_DIR)/app/build.gradle \
clean \
assembleDebug

tun2socks:
android-testbed: $(ANDROID_TESTBED)

$(TUN2SOCKS):
cd $(LANTERN_MOBILE_DIR) && ndk-build
mkdir -p $(LANTERN_MOBILE_DIR)/app/libs/armeabi-v7a
cp $(LANTERN_MOBILE_DIR)/libs/armeabi-v7a/libtun2socks.so $(LANTERN_MOBILE_DIR)/app/libs/armeabi-v7a/libtun2socks.so

$(APK_FILE): build-android-debug
$(LANTERN_MOBILE_TUN2SOCKS): $(TUN2SOCKS)
mkdir -p $(LANTERN_MOBILE_LIBS) && \
cp $(TUN2SOCKS) $(LANTERN_MOBILE_TUN2SOCKS)

$(LANTERN_MOBILE_ANDROID_LIB): $(ANDROID_LIB)
mkdir -p $(LANTERN_MOBILE_LIBS) && \
cp $(ANDROID_LIB) $(LANTERN_MOBILE_ANDROID_LIB)

$(LANTERN_MOBILE_ANDROID_SDK): $(ANDROID_SDK)
mkdir -p $(LANTERN_MOBILE_LIBS) && \
cp $(ANDROID_SDK) $(LANTERN_MOBILE_ANDROID_SDK)

$(LANTERN_MOBILE): $(LANTERN_MOBILE_TUN2SOCKS) $(LANTERN_MOBILE_ANDROID_LIB) $(LANTERN_MOBILE_ANDROID_SDK)
cd $(LANTERN_MOBILE_DIR)/app
gradle -b $(LANTERN_MOBILE_DIR)/app/build.gradle \
clean \
assembleDebug

android-install:
adb install -r $(APK_FILE)
android: $(LANTERN_MOBILE)

android-uninstall: $(APK_FILE)
adb uninstall -r $(ANDROID_PACKAGE)
android-debug: $(LANTERN_MOBILE)

android-run:
$(call pkg_variables)
echo $(PACKAGE)
echo $(MAIN_ACTIVITY)
adb shell am start -n $(PACKAGE)/$(MAIN_ACTIVITY)
adb logcat | grep `adb shell ps | grep org.getlantern.lantern | cut -c10-15`
android-install: $(LANTERN_MOBILE)
adb install -r $(LANTERN_MOBILE)

clean:
@rm -f lantern_linux* && \
rm -f lantern_linux* && \
rm -f lantern_darwin* && \
rm -f lantern_windows* && \
rm -f lantern-installer* && \
Expand All @@ -559,5 +588,14 @@ clean:
git checkout ./src/github.com/getlantern/flashlight/ui/resources.go && \
rm -f src/github.com/getlantern/flashlight/*.syso && \
rm -f *.dmg && \
rm -rf $(MOBILE_TESTBED_LIBS)/$(LANTERN_MOBILE_LIBRARY) && \
rm -rf $(MOBILE_SDK_LIBS)/$(LANTERN_MOBILE_LIBRARY)
rm -f $(ANDROID_LIB) && \
rm -f $(ANDROID_SDK_ANDROID_LIB) && \
rm -f $(ANDROID_SDK) && \
rm -f $(ANDROID_TESTBED_ANDROID_LIB) && \
rm -f $(ANDROID_TESTBED_ANDROID_SDK) && \
rm -f $(ANDROID_TESTBED) && \
rm -f $(LANTERN_MOBILE_TUN2SOCKS) && \
rm -f $(LANTERN_MOBILE_ANDROID_LIB) && \
rm -f $(LANTERN_MOBILE_ANDROID_SDK) && \
rm -rf $(LANTERN_MOBILE_DIR)/libs/armeabi* && \
rm -f $(LANTERN_MOBILE)
72 changes: 40 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,60 +251,67 @@ VERSION=2.0.0-beta5 GH_TOKEN=$GITHUB_TOKEN make release
You can provide a different directory by passing the `LANTERN_BINARIES_PATH`
env variable.

## Other tasks
## Mobile

### Creating the Android embeddable library
### Mobile Prerequisites

In order to build the Android ARM library that can be embedded in applications,
Lantern is using `gomobile`. This simplifies the process notably.
Building the mobile library and app requires the following:

Currently, as Go 1.5 is not stable, a specific git revision is used within an
isolated Docker image.
1. Install Java JDK 7 or 8
2. Install Go 1.6rc1 or higher
3. Install [Android SDK Tools](http://developer.android.com/sdk/index.html#Other)
4. Install NDK(http://developer.android.com/ndk/downloads/index.html)

To build a development library (takes shorter time):
Make sure to set these environment variables before trying to build any Android
components (replace the paths based on wherever you've installed the Android
SDK and NDK).

```bash
export ANDROID_HOME=/opt/adt-bundle-mac-x86_64-20130917/sdk
export PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools:$PATH
export NDK_HOME=/opt/android-ndk-r10e
export PATH=$NDK_HOME:$PATH
```
make android-lib
```

To build the final version for Firetweet:
### Go Android Library

The core Lantern functionality can be packaged into a native Android library
with:

```
make android-lib-dist
make android-lib
```

If you pass the `FIRETWEET_MAIN_DIR` env variable to `make android-lib`, the
generated bindings and library will be copied into it:
### Java Android SDK

The Java-based Android SDK allows easy embedding of Lantern functionality in 3rd
party Android apps such as Manoto TV. The SDK can be built with:

```
FIRETWEET_MAIN_DIR=/path/to/firetweet/src/main make android-lib
make android-sdk
```

You can also override this environment variable if you want to use the
[Flashlight Android Tester](https://github.com/getlantern/lantern-mobile-single-app-example) app.
### Lantern Mobile Testbed

#### Creating the Android library without docker
This simple Android application provides a way to test the Android SDK. It can
be built with:

1. Install Java JDK 7 or 8
2. Install [Android SDK Tools](http://developer.android.com/sdk/index.html#Other)
3. Install NDK(http://developer.android.com/ndk/downloads/index.html)
4. Install [gomobile](https://godoc.org/golang.org/x/mobile/cmd/gomobile)
```
make android-testbed
```

Useful environment variables (replace the paths based on wherever you've
installed the Android SDK and NDK).
### Lantern Mobile App

```bash
export ANDROID_HOME=/opt/adt-bundle-mac-x86_64-20130917/sdk
export PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools:$PATH
export NDK_HOME=/opt/android-ndk-r10e
export PATH=$NDK_HOME:$PATH
To build the full lantern mobile app:

```
make android-debug
```
)

Then to build the library:
To install on the default device:

```bash
make android-lib-local
```
make android-install
```

### Android Tips
Expand Down Expand Up @@ -365,6 +372,7 @@ HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Connection", "close");
```

## Other
### Generating assets

```sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@

import org.getlantern.lantern.android.vpn.Tun2Socks;

/**
* <p>This code is largely based on Shadowsocks code from
* <a href="https://github.com/andforce/SmartZPN/tree/master/app/src/main/java/org/zarroboogs/smartzpn">here</a>.</p>
*
* <p>The tun2socks code came from
* <a href="https://github.com/ambrop72/badvpn/tree/master/tun2socks">here</a>.</p>
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public class VpnBuilder extends VpnService {

Expand Down

0 comments on commit e3c9e61

Please sign in to comment.