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 support #2

Closed
MisterDA opened this issue Jul 20, 2014 · 14 comments
Closed

Android support #2

MisterDA opened this issue Jul 20, 2014 · 14 comments
Assignees

Comments

@MisterDA
Copy link
Owner

I am trying to make the script support the Löve port to android, but it doesn't work yet. See the branch love-release/tree/android.
Try it with command -a (might be temporary).

It requires that you have a working Android NDK installed, see Building LÖVE for Android, and also Git and Ant must be installed.

I'm trying to reproduce and automates the steps described in Game packaging.
Any advices or contributions of any kind would be helpful.

@MisterDA MisterDA self-assigned this Jul 20, 2014
@josefnpat
Copy link

I wrote most of the docs for love-android-sdl2; if there's anything I can help with, please tell me.

@pablomayobre
Copy link
Contributor

Well I see that you update the version by default... that is not a good idea always. You should leave that to the user.

You should check that the .love version is as new as the love-android version (if love is 0.8 there would be lots of errors)
Also when updating the manifest you use a predefined manifest, so if versions go up or I use another version I should change the script... it would be better to read it somehow (you are using many side programs so it might not be bad to add a new one) and changing the parts that we need

Icons are a good thing to have but I dont know how you implemented that in other versions (I think that it is similar to the debian package but you dont take part in the icon process there because they are easily changed as files in a zip... something imposible with apks)

I think the rest is rather good and it should compile

I'll help when I have time and linux in my machine.

@MisterDA
Copy link
Owner Author

Well... Here is how I intend to do it.

We check if love-android-sld2 has already been downloaded:

  • if not, clone love-android-sdl2 then launch ndk-build
  • if so:
    • delete the previously generated files (basically the ones listed in .gitignore, because i'm not shure they should stay here. Maybe they are regenerated at each build, but still...)
    • git checkout to reset AndroidManifest.xml and the GameActivity.java file
    • git pull to get it updated.

Then, we copy the love file in assets/game.love.
After that, we override the AndroidManifest.xml and we launch ant debug.
And then we copy the bin/love_android_sdl2-debug.apk to the release directory.
Easy.

I also think it is better to parse the Manifest rather than use a predefined one, but that was a first try.
How could I parse it ? With grep, awk, or something ? Or with a real XML-parser ?
For now, when I try it, it fails.

I have noticed a thing that intriguated me in the docs.

You should now have a apk that should run on your device located at:
~/bin/love_android_sdl2-debug.apk

It's not ~/bin, it's rather the love-android-sdl2\bin, isn't it ? And is the name always love_android_sdl2-debug.apk, or does it depends of the name of the game ?

For the icons, it is a great problem. I think it requires another issue, we'll see later. I'd like to get this thing working first.

@josefnpat
Copy link

if you are going to clone the love-android-sdl2 every time, you will have to run ndk-build on the repo as well.

As for the file location, thanks; I've updated to docs.

The apk should be located here:
./bin/love_android_sdl2-debug.apk

And assuming you use ant debug, it will always be named that.

@pablomayobre
Copy link
Contributor

Well your idea is not bad... to answer some questions, yeah the files are generated every time you compile, yes it s love-android-sdl2\bin and yes it is named love_android_sdl2-debug.apk because that is the name defined in the build.xml files, also it is a debug release (ant debug) instead of a signed apk.

To parse the manifest I think that grep could work with -i -w -n and some processing in the output (I dont know how to use awk)

1 similar comment
@pablomayobre
Copy link
Contributor

Well your idea is not bad... to answer some questions, yeah the files are generated every time you compile, yes it s love-android-sdl2\bin and yes it is named love_android_sdl2-debug.apk because that is the name defined in the build.xml files, also it is a debug release (ant debug) instead of a signed apk.

To parse the manifest I think that grep could work with -i -w -n and some processing in the output (I dont know how to use awk)

@MisterDA
Copy link
Owner Author

I had forget the ndk-build. I improved a bit the way it handles when to clone the repo with de4f6ef.
I always get this error when I run it...

Buildfile: ~/.cache/love-release/0.9.1/love-android-sdl2/build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 23.0.2
 [checkenv] Installed at /opt/android-sdk

-setup:
     [echo] Project Name: love_android_sdl2
  [gettype] [Fatal Error] :2:6: The processing instruction target matching "[xX][mM][lL]" is not allowed.

BUILD FAILED
/opt/android-sdk/tools/ant/build.xml:407: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; The processing instruction target matching "[xX][mM][lL]" is not allowed.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
    at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:466)
    at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:513)
    at com.android.ant.GetTypeTask.execute(GetTypeTask.java:85)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.Main.runBuild(Main.java:851)
    at org.apache.tools.ant.Main.startAnt(Main.java:235)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
--------------- linked to ------------------
javax.xml.xpath.XPathExpressionException: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; The processing instruction target matching "[xX][mM][lL]" is not allowed.
    at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:471)
    at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:513)
    at com.android.ant.GetTypeTask.execute(GetTypeTask.java:85)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.Main.runBuild(Main.java:851)
    at org.apache.tools.ant.Main.startAnt(Main.java:235)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; The processing instruction target matching "[xX][mM][lL]" is not allowed.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
    at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:466)
    ... 18 more

Total time: 0 seconds

@pablomayobre
Copy link
Contributor

ndk build can take hours... I dont want to run ndk build every single time I compile an apk

Your error seems to be a problem with android-sdk tools... someone had a similar issue wait a bit and I'll search

@MisterDA
Copy link
Owner Author

No ! With this snippet, if it can't find the repo in the cache, it just clones the repo and then run the ndk-build, otherwise it checks if the repo is up-to-date. If it is not, git pull then it runs again the ndk-build. If the repo has already been downloaded, there is no need to run ndk-build, and only ant will be run later.

  if [ -d "$LOVE_ANDROID_DIR" ]; then
    cd "$LOVE_ANDROID_DIR"
    git checkout -- .
    rm -rf src/com
    LOCAL=$(git rev-parse @)
    REMOTE=$(git rev-parse @{u})
    BASE=$(git merge-base @ @{u})
    if [ $LOCAL = $REMOTE ]; then
      :
    elif [ $LOCAL = $BASE ]; then
      git pull
      ndk-build --jobs $(( $(nproc) + 1))
    fi
    cd "$RELEASE_DIR"
  else
    cd "$CACHE_DIR"
    git clone https://bitbucket.org/MartinFelis/love-android-sdl2.git
    cd "$LOVE_ANDROID_DIR"
    ndk-build --jobs $(( $(nproc) + 1))
    cd "$RELEASE_DIR"
  fi

For the error, it must be someting I'm doing wrong with the AndroidManifest... IBM says it's because the XML is not valid. Need to check that.
ndk-build must be run once at every love-android-sdl2 update at the root of the repo, and ant debug every time we want a new package, at the root of the repo too. Am I right ?

@MisterDA
Copy link
Owner Author

Okay ! It's done ! The build was failing because I left a new line at the beginning of the XML file. Now it should perfectely work. Still, if you could test it with differents projects, make sure it's working.
Next steps before merging: parse the AndroidManifest, and the version test.
When it's done, i'll close the issue.

@pablomayobre
Copy link
Contributor

Mmmm yeah that would work. What about parsing the xml?

@MisterDA
Copy link
Owner Author

It's not really parsing, I guess, it's merely replacing strings...
It's easy to do sed -i 's/GameActivity/$ACTIVITY/g' AndroidManifest.xml, but I can't do the same with LÖVE for Android...

<application
      android:label="LÖVE for Android" >
      <activity
         android:label="LÖVE for Android" >

should go to

<application
      android:label="ProjectName ProjectVersion" >
      <activity
         android:label="ProjectName" >

Maybe if I ask for a non-greedy search it will stop at the first occurence found and then I re-launch it to replace the second "LÖVE for Android". At the exception of this point, it should be easy to do. But for now it'll have to wait a couple of hours.

And should I keep the -a option for Android ? Or maybe --android or --apk instead ?
Is an --activity option required to set the name of the class that will extend GameActivity ? By default the name of the class is ${PROJECT_NAME// /_}Activity.

@MisterDA
Copy link
Owner Author

I have erased the predefined AndroidManifest, and replaced it with this:

MAINTAINER_USERNAME=${MAINTAINER_NAME// /_}
ACTIVITY=${PROJECT_NAME// /_}Activity
ANDROID_VERSION=$(grep -Eo -m 1 "[0-9]+.[0-9]+.[0-9]+[a-z]*" "$LOVE_ANDROID_DIR"/AndroidManifest.xml)
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)."
else
  mkdir -p "$LOVE_ANDROID_DIR"/assets
  cp "$PROJECT_NAME".love "$LOVE_ANDROID_DIR"/assets/game.love
  cd "$LOVE_ANDROID_DIR"
  sed -i "s/org.love2d.android/com.${MAINTAINER_USERNAME}.${PACKAGE_NAME}/" AndroidManifest.xml
  sed -i "s/$ANDROID_VERSION/${ANDROID_VERSION}-${PACKAGE_NAME}-v${PROJECT_VERSION}/" AndroidManifest.xml
  sed -i "0,/LÖVE for Android/s//$PROJECT_NAME $PROJECT_VERSION/" AndroidManifest.xml
  sed -i "s/LÖVE for Android/$PROJECT_NAME/" AndroidManifest.xml
  sed -i "s/GameActivity/$ACTIVITY/" AndroidManifest.xml
  # ...
fi

@MisterDA
Copy link
Owner Author

Okay... I think it's done. An android package must be released alone, it is not possible to make at the same time a release for (by example) Windows or another Debian package. Just to prevent some ugly things that could happen.
This is the help:

OPERATING SYSTEMS

-a
Create an Android package. In order to create an Android package, you must have installed the Android SDK. See Building LÖVE for Android, but there is no need to install the LÖVE port to Android, as the script will handle this by itself. You also might want to provide more informations about it. See the ANDROID section below.

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.
--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.
--maintainer-name Set the maintainer’s name. The company name is used by default. It must be only alphanumerical characters, with eventual underscores.
--package-name Set the name of the package. By default, it is the name of your project, with eventual spaces replaced by underscores.
--update-repo Update the love-android-sdl2.git repository used in the cache.
--version Set the version of your package.

Now I have to merge the changes, and there are a few things that needs to be rewritten in the whole script. I am going to open #3 about icons support. Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants