Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android build fixes for Linux and MacOS #114

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Project
# Intermediate
pkg/android/app/src/main/java/com/zerotier/libzt/*.java
ports/android/app/src/main/java/com/zerotier/libzt/*.java
ports/java/com/zerotier/libzt/*.java
ports/xcode_ios-arm64/
Expand Down Expand Up @@ -40,8 +41,10 @@ zerotier-one.port
*.bin
*.framework
*.jar
!gradle-wrapper.jar
bin/
gen/
*.plist

# Keyfiles, etc
*.keystore
Expand Down Expand Up @@ -78,6 +81,7 @@ obj/
.cxx
app/.cxx
app/.cxx/
cache/

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Peer-to-peer and cross-platform encrypted connections built right into your app
| Node.js | See [examples/nodejs](./examples/nodejs) |<img src="https://img.shields.io/badge/-help--wanted-green"/>|[Node.js](./examples/nodejs) |
| Linux | [Build from source](#build-from-source) | <img alt="version" src="https://img.shields.io/github/v/tag/zerotier/libzt?label="/></a>| [C/C++](./examples/cpp) |
| macOS | `brew install libzt`|<a href="https://formulae.brew.sh/formula/libzt#default"><img src="https://img.shields.io/homebrew/v/libzt?label=Homebrew"/></a> | [C/C++](./examples/cpp), [Objective-C](./examples/objective-c) |
| iOS / iPadOS | `./build.sh ios-framework` | <img src="https://img.shields.io/github/v/tag/zerotier/libzt?label="/>| [Objective-C](./examples/objective-c), [Swift](./examples/swift) |
| iOS / iPadOS | `./build.sh xcframework` | <img src="https://img.shields.io/github/v/tag/zerotier/libzt?label="/>| [Objective-C](./examples/objective-c), [Swift](./examples/swift) |
| Android |`./build.sh android-aar` | <img src="https://img.shields.io/github/v/tag/zerotier/libzt?label="/> | [Java](./examples/java) |

<br>
Expand Down Expand Up @@ -75,9 +75,9 @@ Example output:
```
~/libzt/dist/macos-x64-host-release
├── bin
   ├── client
   ├── server
   └── ...
├── client
├── server
└── ...
└── lib
├── libzt.a
└── libzt.dylib
Expand Down
51 changes: 32 additions & 19 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
# | SYSTEM DISCOVERY AND CONFIGURATION |
# -----------------------------------------------------------------------------

# Git refresh
git submodule update --init

# Environment Variables
[ -z "$ANDROID_HOME" ] && [ -d ~/Android/Sdk ] && export ANDROID_HOME=~/Android/Sdk && echo 'export ANDROID_HOME=~/Android/Sdk' >> ~/.profile && echo 'export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin' >> ~/.profile
[ -z "$ANDROID_SDK_ROOT" ] && [ -d ~/Android/Sdk ] && export ANDROID_SDK_ROOT=~/Android/Sdk && echo 'export ANDROID_SDK_ROOT=~/Android/Sdk' >> ~/.profile
[ -z "$ANDROID_AVD_HOME" ] && [ -d ~/.android/avd ] && export ANDROID_AVD_HOME=~/.android/avd && echo 'export ANDROID_AVD_HOME=~/.android/avd' >> ~/.profile

# Find and set cmake
CMAKE=cmake3
if [[ $(which $CMAKE) = "" ]];
Expand Down Expand Up @@ -73,6 +81,9 @@ DEFAULT_HOST_BIN_OUTPUT_DIR=$BUILD_OUTPUT_DIR/$HOST_PLATFORM-$HOST_MACHINE_TYPE
DEFAULT_HOST_PKG_OUTPUT_DIR=$BUILD_OUTPUT_DIR/$HOST_PLATFORM-$HOST_MACHINE_TYPE
# Defaultlocation for CMake's caches (when building for host)
DEFAULT_HOST_BUILD_CACHE_DIR=$BUILD_CACHE_DIR/$HOST_PLATFORM-$HOST_MACHINE_TYPE
# Headers
[ ! -f /usr/lib/jvm/java-8-openjdk-amd64/include/jni_md.h ] && [ -f /usr/lib/jvm/java-8-openjdk-amd64/include/linux/jni_md.h ] && sudo ln -s /usr/lib/jvm/java-8-openjdk-amd64/include/linux/jni_md.h /usr/lib/jvm/java-8-openjdk-amd64/include/jni_md.h
[ ! -f /usr/lib/jvm/java-11-openjdk-amd64/include/jni_md.h ] && [ -f /usr/lib/jvm/java-11-openjdk-amd64/include/linux/jni_md.h ] && sudo ln -s /usr/lib/jvm/java-11-openjdk-amd64/include/linux/jni_md.h /usr/lib/jvm/java-11-openjdk-amd64/include/jni_md.h

gethosttype()
{
Expand All @@ -97,11 +108,11 @@ gethosttype()
# └── zt.xcframework
# ├── Info.plist
# ├── ios-arm64
# │   └── zt.framework
# │   └── ...
# │ └── zt.framework
# │ └── ...
# ├── ios-arm64_x86_64-simulator
# │   └── zt.framework
# │   └── ...
# │ └── zt.framework
# │ └── ...
# └── macos-arm64_x86_64
# └── zt.framework
# └── ...
Expand Down Expand Up @@ -153,10 +164,10 @@ xcframework()
# └── pkg
# └── zt.framework
# ├── Headers
# │   └── ZeroTierSockets.h
# │ └── ZeroTierSockets.h
# ├── Info.plist
# ├── Modules
# │   └── module.modulemap
# │ └── module.modulemap
# └── zt
#
iphonesimulator-framework()
Expand Down Expand Up @@ -202,10 +213,10 @@ iphonesimulator-framework()
# └── pkg
# └── zt.framework
# ├── Headers
# │   └── ZeroTierSockets.h
# │ └── ZeroTierSockets.h
# ├── Info.plist
# ├── Modules
# │   └── module.modulemap
# │ └── module.modulemap
# └── zt
#
macos-framework()
Expand Down Expand Up @@ -248,10 +259,10 @@ macos-framework()
# └── pkg
# └── zt.framework
# ├── Headers
# │   └── ZeroTierSockets.h
# │ └── ZeroTierSockets.h
# ├── Info.plist
# ├── Modules
# │   └── module.modulemap
# │ └── module.modulemap
# └── zt
#
iphoneos-framework()
Expand Down Expand Up @@ -295,12 +306,12 @@ iphoneos-framework()
# - Build output : /Volumes/$USER/zt/libzt/libzt-dev/dist
#
# linux-x64-host-release
# ├── bin
# │   ├── client
# │   └── server
# └── lib
#  ├── libzt.a
#  └── libzt.so # .dylib, .dll
# ├── bin
# ├── client
# └── server
# └── lib
# ├── libzt.a
# └── libzt.so # .dylib, .dll
#
host()
{
Expand Down Expand Up @@ -394,7 +405,7 @@ host-jar()
JAVA_JAR_DIR=$CACHE_DIR/pkg/jar
JAVA_JAR_SOURCE_TREE_DIR=$JAVA_JAR_DIR/com/zerotier/libzt/
mkdir -p $JAVA_JAR_SOURCE_TREE_DIR
cp -f src/bindings/java/*.java $JAVA_JAR_SOURCE_TREE_DIR
cp -f ext/ZeroTierOne/java/src/com/zerotier/sdk/*.java $JAVA_JAR_SOURCE_TREE_DIR
# Build
$CMAKE $VARIANT -H. -B$CACHE_DIR -DCMAKE_BUILD_TYPE=$BUILD_TYPE
$CMAKE --build $CACHE_DIR $BUILD_CONCURRENCY
Expand Down Expand Up @@ -447,6 +458,8 @@ fi
# android-any-android-release
# └── libzt-release.aar
#
# Dependency: sudo apt install ninja-build
#
android-aar()
{
ARTIFACT="android"
Expand All @@ -462,7 +475,7 @@ android-aar()
rm -rf ext/ZeroTierOne/ext/miniupnpc/VERSION
export PATH=$ANDROID_HOME/cmdline-tools/tools/bin:$PATH
# Copy source files into project
cp -f src/bindings/java/*.java ${ANDROID_PKG_PROJ_DIR}/app/src/main/java/com/zerotier/libzt
cp -f ext/ZeroTierOne/java/src/com/zerotier/sdk/*.java ${ANDROID_PKG_PROJ_DIR}/app/src/main/java/com/zerotier/libzt
# Build
UPPERCASE_BUILD_TYPE="$(tr '[:lower:]' '[:upper:]' <<< ${BUILD_TYPE:0:1})${BUILD_TYPE:1}"
CMAKE_FLAGS="-D${CMAKE_SWITCH}=1 -D${CMAKE_SWITCH}=ON"
Expand Down Expand Up @@ -514,7 +527,7 @@ clean()
rm -rf *.cmake
rm -rf CMakeCache.txt
rm -rf Makefile
# Android AAR project binaries and sources (copied from src/bindings/java)
# Android AAR project binaries and sources (copied from ext/ZeroTierOne/java)
rm -rf $ANDROID_PKG_PROJ_DIR/app/build
rm -rf $ANDROID_PKG_PROJ_DIR/app/src/main/java/com/zerotier/libzt/*.java
rm -rf $ANDROID_PKG_PROJ_DIR/app/.externalNativeBuild
Expand Down
1 change: 1 addition & 0 deletions examples/cpp/client.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <string>
#include <arpa/inet.h>

#include "ZeroTierSockets.h"

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/comprehensive.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <arpa/inet.h>

#include "ZeroTierSockets.h"

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/nonblockingclient.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
#include <stdlib.h>
#include <string.h>
#include <string>
#include <arpa/inet.h>

#include "ZeroTierSockets.h"

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/nonblockingserver.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>

#include "ZeroTierSockets.h"

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/server.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <string>
#include <arpa/inet.h>

#include "ZeroTierSockets.h"

Expand Down
5 changes: 0 additions & 5 deletions include/ZeroTierSockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,6 @@ struct zts_virtual_network_route
*/
#define ZTS_MAX_NETWORK_SHORT_NAME_LENGTH 127

/**
* Maximum number of pushed routes on a network
*/
#define ZTS_MAX_NETWORK_ROUTES 32

/**
* Maximum number of statically assigned IP addresses per network endpoint using ZT address management (not DHCP)
*/
Expand Down
21 changes: 10 additions & 11 deletions pkg/android/app/build.gradle
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion 30
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -13,11 +13,6 @@ android {
cppFlags ""
}
}
ndk {
// Tells Gradle to build outputs for the following ABIs and package
// them into your APK.
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
}
buildTypes {
release {
Expand All @@ -27,16 +22,20 @@ android {
}
externalNativeBuild {
cmake {
version "3.19.0+"
path "../../../CMakeLists.txt"
}
ndkBuild{
path "../../../ext/ZeroTierOne/java/jni/Android.mk"
}
}
}


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
}
6 changes: 3 additions & 3 deletions pkg/android/build.gradle
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ buildscript {

repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:4.1.3'


// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -18,7 +18,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/android/gradle.properties
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.useAndroidX=true
android.enableJetifier=true
Binary file added pkg/android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pkg/android/gradle/wrapper/gradle-wrapper.properties
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
Loading