Deploy Hello World to Android (using OSX)


#1

I am on OS X.  I would like to get ./JUCE-master/extras/example\ projects/HelloWorld.jucer building onto my Android device.

I have just successfully created a new workspace in eclipse containing a hello-world project, and deployed it to (1) my Android phone and (2) a virtual Android device.

 

Now I am trying to create an Android project using IntroJucer and get eclipse to run it in the same way.

This question follows from http://www.juce.com/forum/topic/basic-example-deploying-multiple-platforms (I can't see how to make a web link on these forums)

But I can't see how to load the project into eclipse.

I create a new workspace in eclipse. I then try to load the project into it, as per http://stackoverflow.com/questions/14220633/how-to-open-an-existing-project-in-eclipse

I'm having trouble getting anywhere in eclipse. Even getting consistent behaviour. The original eclipse-created-project was deploying to my Android phone. And now it is only deploying to the simulator. ARGH.

And I can't see how to load this IntroJucer-generated-project into eclipse.

Looking back through the forum, I can find http://www.juce.com/forum/topic/beginners-tutorial-introjucer-apk-using-windows#p61988 which says that I need to run this project through the NDK before I attempt to load it into eclipse.

But now I'm having trouble running it through NDK. That guide I linked says:

- from there, start ndk-build (it should run if you set the PATH correctly)

I try modifying my path:

pi@piBookAir.local ~ /Users/pi/Desktop/JUCE-master/extras/example projects/Builds/Android:
 ⤐  PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/X11/bin:/Users/pi/Dev/Android\ SDK/ndk
 ✔

pi@piBookAir.local ~ /Users/pi/Desktop/JUCE-master/extras/example projects/Builds/Android:
 ⤐  echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/X11/bin:/Users/pi/Dev/Android SDK/ndk
 ✔

pi@piBookAir.local ~ /Users/pi/Desktop/JUCE-master/extras/example projects/Builds/Android:
 ⤐  pwd
/Users/pi/Desktop/JUCE-master/extras/example projects/Builds/Android
 ✔

pi@piBookAir.local ~ /Users/pi/Desktop/JUCE-master/extras/example projects/Builds/Android:
 ⤐  ndk-build
usage: dirname path
make: /Users/pi/build/core/build-local.mk: No such file or directory
make: *** No rule to make target `/Users/pi/build/core/build-local.mk'.  Stop.
 ✘

This is horrible stumbling. I apologise. Could someone please come to the rescue?


#2

I don't use eclipse myself - other people might be able to give you more advice about that.

But to build from the command-line should be easy if the android build tools are set up - you just switch to the yourproject/Builds/Android folder and run "ant debug" or "ant release"


#3

The following worked for me to create an Hello World (default) android app and upload it to a smartphone.

(this assumes that you have installed Eclipse, Android SDK and NDK).

Eclipse Platform 4.2.1 - ADT 22.0.5 - NDK r9d 64-bit (add path to NDK using Preferences/Android/NDK)

 

- Create a folder where to put the JUCE projects (for instance "/Users/Name/Documents/JuceProjects")

 

From IntroJucer app:

- File/New Project

- Pick the folder where you put the project folder (JuceProjects)

- Project Name: ScratchTest

Thus the project folder will be: /Users/Name/Documents/JuceProjects/ScratchTest ("ScratchTest" at the bottom left)

- Project type: GUI Application

- FIles to auto-generate: main.cpp + basic window

- Create...

JUCE module folder: give the complete path of the "modules" folder

- Click on Config tag and on project name (ScratchTest) if not already selected

- Project Settings: 

Bundle id: com.yourcompany.ScratchTest

- Right-click on the project name (ScratchTest):

Create a new Android Project target

- File/Save Project

 

From Eclipse:

Make sure NDK path has been set: 

Go into Preferences -> Android -> NDK and put in the correct path -- if you haven't downloaded the NDK, you need to do it!

IMPORTANT: make sure your NDK path doesn't contain any spaces, otherwise you'll get: *** No rule to make target `/Users/sk/build/core/build-local.mk'. Stop.

- File/New/Project...

Android Project from Existing Code

Root Directory: /Users/Name/Documents/JuceProjects/ScratchTest/ScratchTest/Builds/Android

Finish

- Edit Manifest.xml (double-click on AndroidManifest.xml in the Package Explorer):

Create the icons (mandatory): click on the Application tag, and then Icon > Browse > Create New icon >  ... Finish

Click on the androidManifest.xml tag and edit the manifest code: 

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>

<application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:allowBackup="false">

Your manifest file should look like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0"

          package="com.yourcompany.scratchtest">

  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"/>

  <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>

  <uses-permission android:name="android.permission.INTERNET"/>

  <uses-feature android:glEsVersion="0x00020000" android:required="true"/>

  <application android:label="@string/app_name" android:icon="@drawable/icon" android:allowBackup="false">

    <activity android:name="ScratchTest" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation">

      <intent-filter>

        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>

      </intent-filter>

    </activity>

  </application>

</manifest>

 Save file (ScratchTest Manifest)

 

- Right-click on project name (ScratchTest)

- Android tools...

Add native support...

lib ScratchTest .so

Finish

If you have not already done it tell Eclipse which version you want to generate (in this example min 8). Eclipse will just have the latest SDK (version 19 at time of writing).

So you have to go into the Eclipse SDK manager: window -> Android SDK manager (if it is not visible, you need to do window -> open perspective -> other -> {select Java default} then it will appear.

- Select ScratchTest project (blue)

- Run/Run Configurations...

Android Application

Click on New launch configuration icon

New configuration

Name: ScratchTest

Project: Browse > ScratchTest

- Target

Always prompt to pick device

- Common

Check Run checkbox

Click on Run button

(you can look at the console to see progress; this can take several minutes...)

In the meantime you can connect your smartphone with a USB cable connected to your Mac

 

IF YOU GET AN ERROR FROM ECLIPSE CHECK THE "PROBLEMS VIEW": 

if it says "android manifest file is missing" this is a known Eclipse bug:

just click on the Run icon (white arrow in green circle; make sure ScratchTest is blue-selected in the Project Explorer).

It will re-do the project build (again, it could take a couple of minutes...) but it should now work:

The "Android Device Chooser" should now appear, along with your phone description: click on it and OK

After a few seconds the app window (Hello World!) should appear on your phone screen...

Good luck...


#4

Thanks Phil, fantastic -- how happy I am to see that hello world speech-bubble!

A couple of errors I ran into that were quite easy to fix:

1) Unable to resolve target 'android-8' -- this error is because IntroJucer spits out an Android SDK-Version 8 project file. And eclipse will just have the latest SDK (version 19 at time of writing).

So you have to go into the Eclipse SDK manager: window -> Android SDK manager (if it is not visible, you need to do window -> open perspective -> other -> {select Java default} then it will appear, what an annoying interface?!)

Then you have to install version 8 of the SDK

Now you can go to project -> properties -> android and check the runtime you want. (I didn't actually bother with this step, and it still works. Because as you can see, the version gets defined in the manifest XML file)

2) NDK folder not set

I can't remember what the error message was, but the solution is to go into Preferences -> Android -> NDK and put in the correct path -- if you haven't downloaded the NDK, you need to do it!

IMPORTANT: make sure your NDK path doesn't contain any spaces, otherwise you'll get: *** No rule to make target `/Users/sk/build/core/build-local.mk'. Stop.
 

 


#5

Thanks. I updated my post above (and corrected a couple of things) so that everything is on one post.

A few comments on your comments :)

1) You can set the min android version in the IntroJucer android project window. This avoids to re-change it next time you save the Juce project. btw beware that the android manifest file will be overwriitten every time you save the project. Jules, it'd be great if you could allow either to prevent this from happening (eg using a check box) or to add a slot where we can copy the manifest file to be generated...

2) Yeah sorry I had noted that but somehow did not paste it into my post above.