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

Package generator #12

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,16 @@ sysinfo.txt
SampleUnityProject/builds
*.sln
*.csproj
localtyics_android_builder/.gradle
*.iml
localtyics_android_builder/.idea/libraries
localtyics_android_builder/.idea/gradle.xml
localtyics_android_builder/.idea/workspace.xml
local.properties
.gradle
compiler.xml
profiles_settings.xml
encodings.xml
localytics_android_builder/.idea/libraries
misc.xml
workspace.xml
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
# Unity Plugins (iOS & Android)

To use these Localytics Plugins for Unity:
- Build and Import the Unity Packages from the LocalyticsPlugin Project into your Unity Project
- Import (or optionally build and import) the Unity Packages from the LocalyticsPlugin Project into your Unity Project
- Setup the SDK within Unity and the native development platforms (setting Localytics App Key and Push notification)
- Start calling the Localytics API from any MonoBehavior

## Building and Importing the Unity Plugin Packages

If you have Unity 2017.3 you should be able to use the unitypackage files that come checked in to this repository inside the `release` folder.

If you want to customize the localytics plugin (for a newer or older version of unity, for instance) keep reading this section.

You will need development environment setup for Unity, Android and/or iOS. After that,

1. Build the Plugins (or use the generated ones from /release folder)
1. Build the Plugins (or use the generated ones from the `release` folder)

When creating the Android plug-in you may either supply your own unity.jar (`unity-classes.jar`) file or use the one already contained in the project (which came from Unity 2017.3). Different versions of unity will require different versions of the `unity-classes.jar` to link against (and may not provide a consistent interface with the provided code). If these files are not present or the wrong version is used you may experience un-anticipated problems in the android build. This jar file is needed for the plugin to be built correctly and it's interface must match that in your completed android project.

The easiest way to get the `unity-classes.jar` file that I know of on MacOS is to create an empty unity project and export the project to Android Studio. The `unity-classes.jar` file will be contained inside this project. Before attempting to generate the pacakages, find the file and copy it over the existing version at:
`localytics_android_builder/app/libs/unity-classes.jar`

Call `generate_packages.sh` or `generate_packages.bat` contained in the root of this repository, depending on your system (OSX or Windows). Make sure the LocalyticsPlugin project is closed when executing these scripts. Otherwise, you may experience issues. The generated packages will be in the 'packages' folder with the respective version x.x.x. (i.e. localytics-unity-android-x.x.x.unitypackage and localytics-unity-ios-x.x.x.unitypackage)

When these scripts are executed they first build the android studio project, `localytics_android_builder` (which produces the compiled localytics code), copy the compiled results into a different folder, and then run a packaging unity script (unity project is located at 'LocalyticsPlugin') to create the '.unitypackage' files.

2. Import the Unity Packages

Go to "Asset" -> "Import Package" -> "Custom Package..." and Navigate to the generated **.unitypackage** for Android and/or iOS in Step 1.
Expand Down Expand Up @@ -44,7 +55,8 @@ You will need development environment setup for Unity, Android and/or iOS. After
4. After you generate and open the XCode project, add the `libsqlite3.tbd` and `libz.tbd` libraries (located under "General" -> "Linked Frameworks and Libraries" in the .xcodeproj settings)

### Android
#### Note: Due to a Unity [bug](https://forum.unity3d.com/threads/android-deployment-error.444133/#post-2876464), you may not be able to build and run with the latest version of Android sdk tools. This has been tested with sdk tools version 25.2.2.
#### Note: The android platform, unity and this plugin may fall out of lock-step with one-another which may cause compatibility issues

1. Inside Unity, `AndroidManifest.xml` is included within "Assets/Plugins/Android" as a sample; you may provide your own. You can also modify the file within the exported Android project, but the changes won't persist if the project is regenerated from Unity. The following changes are needed in the sample `AndroidManifest.xml`, or they need to be added to your existing `AndroidManifest.xml`:
* Replace the android:value in the sample with your Localytics App Key

Expand Down
31 changes: 31 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a commented-out sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/4.1/userguide/tutorial_java_projects.html
*/

/*
// Apply the java plugin to add support for Java
apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}

// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.25'

// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}
*/
22 changes: 20 additions & 2 deletions generate_packages.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
@echo off

:: %1 Requires Unity Path
:: e.g generate_packages.bat D:\Unity5.5.3\Editor\Unity.exe

%1 -batchmode -executeMethod GenerateBundles.GenerateiOSBundle -projectPath %~dp0\SampleUnityProject -quit
%1 -batchmode -executeMethod GenerateBundles.GenerateAndroidBundle -projectPath %~dp0\SampleUnityProject -quit
set ANDROID_PROJECT_NAME="localytics_android_builder"

:: build the java ("android") project

echo "Building jar files..."
cd %ANDROID_PROJECT_NAME%
echo dir
CALL gradlew clean
CALL gradlew jarRelease
cd ..

echo "Copying jar files into place..."
copy %ANDROID_PROJECT_NAME%\app\libs\localytics.jar LocalyticsPlugin\Assets\Plugins\Android
copy %ANDROID_PROJECT_NAME%\app\build\libs\app.jar LocalyticsPlugin\Assets\Plugins\Android\localytics-unity.jar

echo "Generating Packages..."
%1 -batchmode -executeMethod GenerateBundles.GenerateiOSBundle -projectPath %~dp0\LocalyticsPlugin -quit
%1 -batchmode -executeMethod GenerateBundles.GenerateAndroidBundle -projectPath %~dp0\LocalyticsPlugin -quit
echo "Done!"
26 changes: 20 additions & 6 deletions generate_packages.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
#!/bin/bash

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
ANDROID_PROJECT_NAME="localytics-android"

ANDROID_PROJECT_NAME="localytics_android_builder"

#if a path is supplied - use that for the unity executable otherwise default
if (($# == 0))
then
UNITY_PATH="/Applications/Unity/Unity.app/Contents/MacOS/Unity"
UNITY_PATH="/Applications/Unity/Unity.app/Contents/MacOS/Unity"
else
UNITY_PATH=$1
UNITY_PATH=$1
fi

ant -buildfile $ANDROID_PROJECT_NAME/build.xml release
#build the java ("android") project
cd $ANDROID_PROJECT_NAME
./gradlew clean
./gradlew build
cd ..

#extract the needed .jar files
unzip $ANDROID_PROJECT_NAME/app/build/outputs/aar/app-release.aar -d $ANDROID_PROJECT_NAME/app/build/outputs/aar/tmp_files

#copy jar files
cp $ANDROID_PROJECT_NAME/app/build/outputs/aar/tmp_files//libs/localytics.jar LocalyticsPlugin/Assets/Plugins/Android/
cp $ANDROID_PROJECT_NAME/app/build/outputs/aar/tmp_files/classes.jar LocalyticsPlugin/Assets/Plugins/Android/localytics-unity.jar

cp $ANDROID_PROJECT_NAME/bin/classes.jar LocalyticsPlugin/Assets/Plugins/Android/localytics-unity.jar
cp $ANDROID_PROJECT_NAME/libs/localytics.jar LocalyticsPlugin/Assets/Plugins/Android

#execute the custom packaging/bundling scripts in the plugin project
echo -n "Generating packages..."
$UNITY_PATH -batchmode -executeMethod GenerateBundles.GenerateiOSBundle -projectPath $DIR/LocalyticsPlugin -logFile -quit
$UNITY_PATH -batchmode -executeMethod GenerateBundles.GenerateAndroidBundle -projectPath $DIR/LocalyticsPlugin -logFile -quit
echo "Done!"


Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
172 changes: 172 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn () {
echo "$*"
}

die () {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading