Skip to content

Commit 0d9c061

Browse files
committed
First commit
0 parents  commit 0d9c061

27 files changed

+1676
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.iml
2+
.gradle
3+
/.idea
4+
/local.properties
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
.DS_Store
9+
/build
10+
/captures
11+
.externalNativeBuild

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "app/src/v2ray-plugin"]
2+
path = app/src/v2ray-plugin
3+
url = https://github.com/madeye/v2ray-plugin

LICENSE

Lines changed: 622 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## v2ray for Android
2+
3+
[![CircleCI](https://circleci.com/gh/shadowsocks/v2ray-plugin-android.svg?style=svg)](https://circleci.com/gh/shadowsocks/v2ray-plugin-android)
4+
[![API](https://img.shields.io/badge/API-21%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=21)
5+
[![Releases](https://img.shields.io/github/downloads/shadowsocks/v2ray-plugin-android/total.svg)](https://github.com/shadowsocks/v2ray-plugin-android/releases)
6+
[![Language: Kotlin](https://img.shields.io/github/languages/top/shadowsocks/v2ray-plugin-android.svg)](https://github.com/shadowsocks/v2ray-plugin-android/search?l=kotlin)
7+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/46b34df6fe624ef9a46507126f407880)](https://www.codacy.com/app/shadowsocks/v2ray-plugin-android?utm_source=github.com&utm_medium=referral&utm_content=shadowsocks/v2ray-plugin-android&utm_campaign=Badge_Grade)
8+
[![License](https://img.shields.io/github/license/shadowsocks/v2ray-plugin-android.svg)](https://github.com/shadowsocks/v2ray-plugin-android/blob/master/LICENSE)
9+
10+
[v2ray](https://github.com/shadowsocks/v2ray) plugin for [shadowsocks-android](https://github.com/shadowsocks/shadowsocks-android).
11+
12+
<a href="https://play.google.com/store/apps/details?id=com.github.shadowsocks.plugin.v2ray"><img src="https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png" height="48"></a>
13+
14+
### PREREQUISITES
15+
16+
* JDK 1.8
17+
* Go 1.11+
18+
* Android SDK
19+
- Android NDK r19+
20+
21+
### BUILD
22+
23+
You can check whether the latest commit builds under UNIX environment by checking CI status.
24+
25+
* Set environment variable `ANDROID_HOME` to `/path/to/android-sdk`
26+
* (optional) Set environment variable `ANDROID_NDK_HOME` to `/path/to/android-ndk` (default: `$ANDROID_HOME/ndk-bundle`)
27+
* Clone the repo using `git clone --recurse-submodules <repo>` or update submodules using `git submodule update --init --recursive`
28+
* Build it using Android Studio or gradle script
29+
30+
### TRANSLATE
31+
32+
This plugin is an official plugin thus you can see [shadowsocks-android](https://github.com/shadowsocks/shadowsocks-android/blob/master/README.md#translate)'s instructions to translate this plugin's UI.
33+
34+
## OPEN SOURCE LICENSES
35+
36+
<ul>
37+
<li>v2ray: <a href="https://raw.githubusercontent.com/v2ray/v2ray-core/master/LICENSE">MIT</a></li>
38+
</ul>
39+
40+
### LICENSE
41+
42+
Copyright (C) 2017 by Max Lv <<max.c.lv@gmail.com>>
43+
Copyright (C) 2017 by Mygod Studio <<contact-shadowsocks-android@mygod.be>>
44+
45+
This program is free software: you can redistribute it and/or modify
46+
it under the terms of the GNU General Public License as published by
47+
the Free Software Foundation, either version 3 of the License, or
48+
(at your option) any later version.
49+
50+
This program is distributed in the hope that it will be useful,
51+
but WITHOUT ANY WARRANTY; without even the implied warranty of
52+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53+
GNU General Public License for more details.
54+
55+
You should have received a copy of the GNU General Public License
56+
along with this program. If not, see <http://www.gnu.org/licenses/>.

app/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/build
2+
/release
3+
# no tests written yet
4+
/src/androidTest
5+
/src/test
6+
/src/bin
7+
/src/pkg
8+
/src/src
9+
/.deps

app/build.gradle

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import org.apache.tools.ant.taskdefs.condition.Os
2+
import com.android.build.OutputFile
3+
4+
import java.util.regex.Matcher
5+
import java.util.regex.Pattern
6+
7+
apply plugin: 'com.android.application'
8+
9+
apply plugin: 'kotlin-android'
10+
11+
def getCurrentFlavor() {
12+
String task = getGradle().getStartParameter().getTaskRequests().toString()
13+
Matcher matcher = Pattern.compile("(assemble|generate)\\w*(Release|Debug)").matcher(task)
14+
if (matcher.find()) return matcher.group(2).toLowerCase() else {
15+
println "Warning: No match found for $task"
16+
return "debug"
17+
}
18+
}
19+
20+
android {
21+
buildToolsVersion "28.0.3"
22+
compileSdkVersion 28
23+
defaultConfig {
24+
applicationId "com.github.shadowsocks.plugin.v2ray"
25+
minSdkVersion rootProject.minSdkVersion
26+
targetSdkVersion 28
27+
versionCode 1000000
28+
versionName "1.0.0"
29+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
30+
}
31+
buildTypes {
32+
release {
33+
minifyEnabled true
34+
shrinkResources true
35+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
36+
}
37+
}
38+
splits {
39+
abi {
40+
enable true
41+
universalApk true
42+
}
43+
}
44+
sourceSets.main.jniLibs.srcDirs += new File(projectDir, "src/bin")
45+
}
46+
47+
task goBuild(type: Exec) {
48+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
49+
println "Warning: Building on Windows is not supported"
50+
} else {
51+
executable "sh"
52+
args "-c", "src/make.bash " + minSdkVersion
53+
}
54+
}
55+
56+
task goClean(type: Exec) {
57+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
58+
println "Warning: Building on Windows is not supported"
59+
} else {
60+
executable "sh"
61+
args "-c", "src/clean.bash"
62+
}
63+
}
64+
65+
tasks.whenTaskAdded { task ->
66+
if ((task.name == 'javaPreCompileDebug' ||
67+
task.name == 'javaPreCompileRelease')) {
68+
task.dependsOn(goBuild)
69+
}
70+
}
71+
72+
dependencies {
73+
implementation fileTree(dir: 'libs', include: ['*.jar'])
74+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
75+
implementation 'com.github.shadowsocks:plugin:1.0.0'
76+
testImplementation 'junit:junit:4.12'
77+
androidTestImplementation 'androidx.test:runner:1.1.1'
78+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
79+
}
80+
81+
ext.abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, x86: 3, x86_64: 4]
82+
if (getCurrentFlavor() == 'release') android.applicationVariants.all { variant ->
83+
variant.outputs.each { output ->
84+
def offset = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
85+
if (offset != null) output.versionCodeOverride = variant.versionCode + offset
86+
}
87+
}

app/proguard-rules.pro

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
-keepattributes SourceFile,LineNumberTable
18+
-dontobfuscate
19+
20+
# If you keep the line number information, uncomment this to
21+
# hide the original source file name.
22+
#-renamesourcefileattribute SourceFile

app/src/clean.bash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
rm -rf $DIR/.deps
6+
rm -rf $DIR/bin
7+
8+
echo "Successfully clean v2ray"

app/src/main/AndroidManifest.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
package="com.github.shadowsocks.plugin.v2ray">
4+
<uses-feature android:name="android.hardware.touchscreen"
5+
android:required="false"/>
6+
<application android:allowBackup="false"
7+
android:label="v2ray"
8+
android:icon="@mipmap/ic_launcher">
9+
<provider android:name=".BinaryProvider"
10+
android:exported="true"
11+
android:directBootAware="true"
12+
android:authorities="com.github.shadowsocks.plugin.v2ray.BinaryProvider"
13+
tools:ignore="ExportedContentProvider">
14+
<intent-filter>
15+
<action android:name="com.github.shadowsocks.plugin.ACTION_NATIVE_PLUGIN"/>
16+
</intent-filter>
17+
<intent-filter>
18+
<action android:name="com.github.shadowsocks.plugin.ACTION_NATIVE_PLUGIN"/>
19+
<data android:scheme="plugin"
20+
android:host="com.github.shadowsocks"
21+
android:pathPrefix="/v2ray"/>
22+
</intent-filter>
23+
<meta-data android:name="com.github.shadowsocks.plugin.id"
24+
android:value="v2ray"/>
25+
<meta-data android:name="com.github.shadowsocks.plugin.default_config"
26+
android:value="host=test.example.com"/>
27+
</provider>
28+
<activity android:name=".HelpCallback"
29+
android:theme="@style/Theme.AppCompat.Translucent">
30+
<intent-filter>
31+
<action android:name="com.github.shadowsocks.plugin.ACTION_HELP"/>
32+
<category android:name="android.intent.category.DEFAULT"/>
33+
<data android:scheme="plugin"
34+
android:host="com.github.shadowsocks"
35+
android:path="/v2ray"/>
36+
</intent-filter>
37+
</activity>
38+
</application>
39+
</manifest>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.github.shadowsocks.plugin.v2ray
2+
3+
import android.net.Uri
4+
import android.os.ParcelFileDescriptor
5+
import com.github.shadowsocks.plugin.NativePluginProvider
6+
import com.github.shadowsocks.plugin.PathProvider
7+
import java.io.File
8+
import java.io.FileNotFoundException
9+
10+
class BinaryProvider : NativePluginProvider() {
11+
override fun populateFiles(provider: PathProvider) {
12+
provider.addPath("v2ray", 0b111101101)
13+
}
14+
override fun getExecutable() = context!!.applicationInfo.nativeLibraryDir + "/libv2ray.so"
15+
override fun openFile(uri: Uri?): ParcelFileDescriptor = when (uri?.path) {
16+
"/v2ray" -> ParcelFileDescriptor.open(File(getExecutable()), ParcelFileDescriptor.MODE_READ_ONLY)
17+
else -> throw FileNotFoundException()
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.github.shadowsocks.plugin.v2ray
2+
3+
import com.github.shadowsocks.plugin.PluginOptions
4+
5+
class HelpCallback : com.github.shadowsocks.plugin.HelpCallback() {
6+
override fun produceHelpMessage(options: PluginOptions): CharSequence =
7+
"""
8+
host=string
9+
Host header for websocket. (default "cloudfront.com")
10+
11+
mode=string
12+
Transport mode: ws/quic. (default "ws")
13+
14+
path=string
15+
URL path for websocket. (default "/")
16+
17+
security=string
18+
Transport security: none/tls. (default "none")
19+
20+
""".trimIndent()
21+
22+
}
5.5 KB
Loading
2.81 KB
Loading
7.54 KB
Loading
14.1 KB
Loading
23.4 KB
Loading

app/src/main/web_hi_res_512.png

90 KB
Loading

app/src/make.bash

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
function try () {
4+
"$@" || exit -1
5+
}
6+
7+
[ -z "$ANDROID_NDK_HOME" ] && ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle
8+
TOOLCHAIN=$(find $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/* -maxdepth 1 -type d -print -quit)/bin
9+
10+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
11+
MIN_API=$1
12+
TARGET=$DIR/bin
13+
14+
try mkdir -p $TARGET/armeabi-v7a $TARGET/x86 $TARGET/arm64-v8a $TARGET/x86_64
15+
16+
export GOPATH=$DIR
17+
18+
pushd $DIR/v2ray-plugin
19+
20+
if [ ! -f "$TARGET/armeabi-v7a/libv2ray.so" ] || [ ! -f "$TARGET/arm64-v8a/libv2ray.so" ] ||
21+
[ ! -f "$TARGET/x86/libv2ray.so" ] || [ ! -f "$TARGET/x86_64/libv2ray.so" ]; then
22+
23+
echo "Get dependences for v2ray"
24+
go get -v
25+
26+
echo "Cross compile v2ray for arm"
27+
if [ ! -f "$TARGET/armeabi-v7a/libv2ray.so" ]; then
28+
try env CGO_ENABLED=1 CC=$TOOLCHAIN/armv7a-linux-androideabi${MIN_API}-clang GOOS=android GOARCH=arm GOARM=7 \
29+
go build -ldflags="-s -w" -o client
30+
try $TOOLCHAIN/arm-linux-androideabi-strip client
31+
try mv client $TARGET/armeabi-v7a/libv2ray.so
32+
fi
33+
34+
echo "Cross compile v2ray for arm64"
35+
if [ ! -f "$TARGET/arm64-v8a/libv2ray.so" ]; then
36+
try env CGO_ENABLED=1 CC=$TOOLCHAIN/aarch64-linux-android${MIN_API}-clang GOOS=android GOARCH=arm64 \
37+
go build -ldflags="-s -w" -o client
38+
try $TOOLCHAIN/aarch64-linux-android-strip client
39+
try mv client $TARGET/arm64-v8a/libv2ray.so
40+
fi
41+
42+
echo "Cross compile v2ray for 386"
43+
if [ ! -f "$TARGET/x86/libv2ray.so" ]; then
44+
try env CGO_ENABLED=1 CC=$TOOLCHAIN/i686-linux-android${MIN_API}-clang GOOS=android GOARCH=386 \
45+
go build -ldflags="-s -w" -o client
46+
try $TOOLCHAIN/i686-linux-android-strip client
47+
try mv client $TARGET/x86/libv2ray.so
48+
fi
49+
50+
echo "Cross compile v2ray for amd64"
51+
if [ ! -f "$TARGET/x86_64/libv2ray.so" ]; then
52+
try env CGO_ENABLED=1 CC=$TOOLCHAIN/x86_64-linux-android${MIN_API}-clang GOOS=android GOARCH=amd64 \
53+
go build -ldflags="-s -w" -o client
54+
try $TOOLCHAIN/x86_64-linux-android-strip client
55+
try mv client $TARGET/x86_64/libv2ray.so
56+
fi
57+
58+
popd
59+
60+
fi
61+
62+
echo "Successfully build v2ray"

app/src/v2ray-plugin

Submodule v2ray-plugin added at 8419334

build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
apply plugin: 'com.github.ben-manes.versions'
4+
5+
buildscript {
6+
ext {
7+
kotlinVersion = '1.3.11'
8+
minSdkVersion = 21
9+
}
10+
repositories {
11+
google()
12+
jcenter()
13+
}
14+
dependencies {
15+
classpath 'com.android.tools.build:gradle:3.2.1'
16+
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
17+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
18+
}
19+
}
20+
21+
allprojects {
22+
repositories {
23+
google()
24+
jcenter()
25+
}
26+
}
27+
28+
task clean(type: Delete) {
29+
delete rootProject.buildDir
30+
}

0 commit comments

Comments
 (0)