Skip to content

Commit

Permalink
Android pkg now supports icons through --apk-icon. #3
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterDA committed Sep 19, 2014
1 parent de470cb commit 02f1738
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 24 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,20 @@ it will automatically detect which version your project uses.
#### ANDROID
Note that every argument passed to the options should be alphanumerical,
with eventual underscores (i.e. [a-zA-Z0-9\_]), otherwise you'll get errors.
`--apk-icon` Path to a single folder where icons are stored.
The script will first look up for filename that contains
`42x42`, `72x72`, `96x96` or `144x144`.
It will then search the icon directory for subdirectories like
`drawable-mdpi`, `drawable-hdpi`, `drawable-xhdpi` and `drawable-xxhdpi`
to find an `ic_launcher.png` image.
`--activity` The name of the class that extends GameActivity.
By default it is the name of the project with ‘Activity’ appended,
eventual spaces and dashes replaced by underscores.
`--apk-maintainer-name` Set the maintainer’s name.
It must be only alphanumerical characters, with eventual underscores.
`--apk-package-name` Set the name of the package.
By default, it is the name of your project, with eventual spaces replaced by underscores.
`--apk-package-version` Set the version of your package.
`--apk-package-version` Set the version of your package.
`--update-android` Update the love-android-sdl2.git repository used in the cache.

#### OTHERS
Expand Down
2 changes: 1 addition & 1 deletion completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _love-release()
opts="-l"
opts="$opts -w --win-icon"
opts="$opts -d --deb-icon --deb-package-version --deb-maintainer-name --maintainer-email --deb-package-name"
opts="$opts -a --activity --apk-package-version --apk-maintainer-name --apk-package-name --update-android"
opts="$opts -a --apk-icon --activity --apk-package-version --apk-maintainer-name --apk-package-name --update-android"
opts="$opts -m --osx-icon --osx-maintainer-name"
opts="$opts -h -n -r -v -x --config --homepage --description --clean --help"

Expand Down
8 changes: 8 additions & 0 deletions love-release.1
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ Set the version of your package.
Note that every argument passed to the options should be alphanumerical,
with eventual underscores (i.e. [a-zA-Z0-9_]), otherwise you'll get errors.
.TP
.B \-\-apk\-icon \fIdir\fR
Path to a single folder where icons are stored.
The script will first look up for filename that contains
\fI42x42\fR, \fI72x72\fR, \fI96x96\fR or \fI144x144\fR.
It will then search the icon directory for subdirectories like
\fIdrawable-mdpi\fR, \fIdrawable-hdpi\fR, \fIdrawable-xhdpi\fR and \fIdrawable-xxhdpi\fR
to find an \fIic_launcher.png\fR image.
.TP
.B \-\-activity \fIactivity\fR
The name of the class that extends GameActivity.
By default it is the name of the project with 'Activity' appended,
Expand Down
6 changes: 3 additions & 3 deletions love-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ SCRIPT_ARGS="w. win-icon: $SCRIPT_ARGS"
SCRIPT_ARGS="d; deb-icon: deb-package-version: deb-maintainer-name: maintainer-email: deb-package-name: $SCRIPT_ARGS"

## Android
SCRIPT_ARGS="a; activity: apk-package-version: apk-maintainer-name: apk-package-name: update-android; $SCRIPT_ARGS"
SCRIPT_ARGS="a; apk-icon: activity: apk-package-version: apk-maintainer-name: apk-package-name: update-android; $SCRIPT_ARGS"

## Mac OS X
SCRIPT_ARGS="m; osx-icon: osx-maintainer-name: $SCRIPT_ARGS"


## List the options that require a file/directory that should be excluded by zip.
EXCLUDE_OPTIONS=("win-icon" "osx-icon" "deb-icon")
EXCLUDE_CONFIG=("INI__windows__icon" "INI__macosx__icon" "INI__debian__icon")
EXCLUDE_OPTIONS=("win-icon" "osx-icon" "deb-icon" "apk-icon")
EXCLUDE_CONFIG=("INI__windows__icon" "INI__macosx__icon" "INI__debian__icon" "INI__android__icon")


## Add a short summary of your platform script here
Expand Down
90 changes: 71 additions & 19 deletions scripts/android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if [ "$CONFIG" = true ]; then
if [ -n "${INI__android__maintainer_name}" ]; then
MAINTAINER_NAME=${INI__android__maintainer_name}
fi
if [ -n "${INI__android__icon}" ]; then
IFS=$'\n'
ICON_DIR=${INI__android__icon}
ICON_FILES=( $(ls -AC1 "$ICON_DIR") )
fi
fi


Expand All @@ -28,6 +33,10 @@ do
if [ "$OPTOPT" = "activity" ]; then
ACTIVITY=$OPTARG
activity_defined_argument=true
elif [ "$OPTOPT" = "apk-icon" ]; then
IFS=$'\n'
ICON_DIR=$OPTARG
ICON_FILES=( $(ls -AC1 "$ICON_DIR") )
elif [ "$OPTOPT" = "apk-package-version" ]; then
PACKAGE_VERSION=$OPTARG
elif [ "$OPTOPT" = "apk-maintainer-name" ]; then
Expand Down Expand Up @@ -91,29 +100,72 @@ ANDROID_VERSION=$(grep -Eo -m 1 "[0-9]+.[0-9]+.[0-9]+[a-z]*" "$LOVE_ANDROID_DIR"
ANDROID_LOVE_VERSION=$(echo "$ANDROID_VERSION" | grep -Eo "[0-9]+.[0-9]+.[0-9]+")

if [ "$LOVE_VERSION" != "$ANDROID_LOVE_VERSION" ]; then
echo "Love version ($LOVE_VERSION) differs from love-android-sdl2 version ($ANDROID_LOVE_VERSION). Could not create package."
exit_module 1 "Love version ($LOVE_VERSION) differs from love-android-sdl2 version ($ANDROID_LOVE_VERSION). Could not create package."
fi

else
mkdir -p "$LOVE_ANDROID_DIR"/assets
cp "$LOVE_FILE" "$LOVE_ANDROID_DIR"/assets/game.love
cd "$LOVE_ANDROID_DIR"
sed -i "s/org.love2d.android/com.${MAINTAINER_NAME}.${PACKAGE_NAME}/" AndroidManifest.xml
sed -i "s/$ANDROID_VERSION/${ANDROID_VERSION}-${PACKAGE_NAME}-v${PACKAGE_VERSION}/" AndroidManifest.xml
sed -i "0,/LÖVE for Android/s//$PROJECT_NAME $PACKAGE_VERSION/" AndroidManifest.xml
sed -i "s/LÖVE for Android/$PROJECT_NAME/" AndroidManifest.xml
sed -i "s/GameActivity/$ACTIVITY/" AndroidManifest.xml
mkdir -p "$LOVE_ANDROID_DIR"/assets
cp "$LOVE_FILE" "$LOVE_ANDROID_DIR"/assets/game.love
cd "$LOVE_ANDROID_DIR"
sed -i "s/org.love2d.android/com.${MAINTAINER_NAME}.${PACKAGE_NAME}/" AndroidManifest.xml
sed -i "s/$ANDROID_VERSION/${ANDROID_VERSION}-${PACKAGE_NAME}-v${PACKAGE_VERSION}/" AndroidManifest.xml
sed -i "0,/LÖVE for Android/s//$PROJECT_NAME $PACKAGE_VERSION/" AndroidManifest.xml
sed -i "s/LÖVE for Android/$PROJECT_NAME/" AndroidManifest.xml
sed -i "s/GameActivity/$ACTIVITY/" AndroidManifest.xml

mkdir -p src/com/$MAINTAINER_NAME/$PACKAGE_NAME
echo "package com.${MAINTAINER_NAME}.${PACKAGE_NAME};
import org.love2d.android.GameActivity;
public class $ACTIVITY extends GameActivity {}
" > src/com/$MAINTAINER_NAME/$PACKAGE_NAME/${ACTIVITY}.java

if [ -n "$ICON_DIR" ]; then
for ICON in "${ICON_FILES[@]}"
do
RES=$(echo "$ICON" | grep -Eo "[0-9]+x[0-9]+")
EXT=$(echo "$ICON" | sed -e 's/.*\.//g')
if [ "$RES" = "42x42" ]; then
cp "$PROJECT_DIR"/"$ICON_DIR"/"$ICON" \
"$LOVE_ANDROID_DIR"/res/drawable-mdpi/ic_launcher.png
echo "HERE"
elif [ "$RES" = "72x72" ]; then
cp "$PROJECT_DIR"/"$ICON_DIR"/"$ICON" \
"$LOVE_ANDROID_DIR"/res/drawable-hdpi/ic_launcher.png
elif [ "$RES" = "96x96" ]; then
cp "$PROJECT_DIR"/"$ICON_DIR"/"$ICON" \
"$LOVE_ANDROID_DIR"/res/drawable-xhdpi/ic_launcher.png
elif [ "$RES" = "144x144" ]; then
cp "$PROJECT_DIR"/"$ICON_DIR"/"$ICON" \
"$LOVE_ANDROID_DIR"/res/drawable-xxhdpi/ic_launcher.png
fi
done
if [ -f "$PROJECT_DIR/$ICON_DIR/drawable-mdpi/ic_launcher.png" ]; then
cp "$PROJECT_DIR"/"$ICON_DIR"/drawable-mdpi/ic_launcher.png \
"$LOVE_ANDROID_DIR"/res/drawable-mdpi/ic_launcher.png
fi
if [ -f "$PROJECT_DIR/$ICON_DIR/drawable-hdpi/ic_launcher.png" ]; then
cp "$PROJECT_DIR"/"$ICON_DIR"/drawable-hdpi/ic_launcher.png \
"$LOVE_ANDROID_DIR"/res/drawable-hdpi/ic_launcher.png
echo "THERE"
fi
if [ -f "$PROJECT_DIR/$ICON_DIR/drawable-xhdpi/ic_launcher.png" ]; then
cp "$PROJECT_DIR"/"$ICON_DIR"/drawable-xhdpi/ic_launcher.png \
"$LOVE_ANDROID_DIR"/res/drawable-xhdpi/ic_launcher.png
fi
if [ -f "$PROJECT_DIR/$ICON_DIR/drawable-xxhdpi/ic_launcher.png" ]; then
cp "$PROJECT_DIR"/"$ICON_DIR"/drawable-xxhdpi/ic_launcher.png \
"$LOVE_ANDROID_DIR"/res/drawable-xxhdpi/ic_launcher.png
fi
fi

mkdir -p src/com/$MAINTAINER_NAME/$PACKAGE_NAME
echo "package com.${MAINTAINER_NAME}.${PACKAGE_NAME};
import org.love2d.android.GameActivity;

public class $ACTIVITY extends GameActivity {}
" > src/com/$MAINTAINER_NAME/$PACKAGE_NAME/${ACTIVITY}.java

ant debug
cp bin/love_android_sdl2-debug.apk "$RELEASE_DIR"
cd "$RELEASE_DIR"
fi

ant debug
cp bin/love_android_sdl2-debug.apk "$RELEASE_DIR"
git checkout -- .
rm -rf src/com bin gen
cd "$RELEASE_DIR"


unset ACTIVITY PACKAGE_NAME PACKAGE_VERSION MAINTAINER_NAME
Expand Down

0 comments on commit 02f1738

Please sign in to comment.