Compiling for Android SDK 1 (Part 5)

Part 1 Installing JDK1.5 and Eclipse Europa
Part 2 Generating R.java and compiling Java source
Part 3 Cross compile to JDK 1.5, convert to dex, package .apk
Part 4 Code sign .apk
Part 5 Troubleshooting and success

The Phaedra .apk would not install on the HTC Dream, or on the second (in the UK at least) Android device the HTC Hero. I'll switch to the HTC Hero as the test device for this experiment as it's not as locked down, you can get to the launcher and use the device without signing in to a Google account or having a SIM card. Once (if?) I get an install working on the Hero I'll switch back to the Dream.

Using the same build process I tried building HelloActivity from the 1.0 SDK examples, this wouldn't install either.

That narrows it down to the build process rather than something in the Phaedra project. Inspecting the output from the bash script more closely I feel stupid because:

3. Compile Java source...
error: Source option 5 is no longer supported. Use 6 or later.
error: Target option 1.5 is no longer supported. Use 1.6 or later.

4. Convert to Dalvik executable (DEX) files...
no classfiles specified

My OpenJDK 11.0.11 install wont cross-compile to Java 1.5, so no class files were being generated, therefore no dex... I should have added error checking to the bash script. Setting the cross-compile target to 1.6, then amending the final aapt to add the classes.dex file makes everything work as expected, will it install?

hello.apk

Yes. That works, here's the final opbl.sh bash file, it needs to be run from the sdk 1.0 tools directory:

#!/bin/bash

echo "Oppen APK build script for Android G1/HTC Dream"
echo "Usage: ./opbl.sh appName /path/to/project path/to/android.jar"
printf "\n"

# Get arguments
# eg. ~/phaedra
name=$1
projectDirectory=$2
androidJar=$3
outputDirectory="${name}_output"
resourceDirectory="$projectDirectory/app/src/main/res"
manifest="$projectDirectory/app/src/main/AndroidManifest.xml"

if [ ! -d "$resourceDirectory" ] 
then
    resourceDirectory="$projectDirectory/res" 
fi

if [ ! -f "$manifest" ] 
then
    manifest="$projectDirectory/AndroidManifest.xml" 
fi

# Generate R.java
echo "1. Generate Android R.java..."
rm -r "$outputDirectory"
mkdir "$outputDirectory"
./aapt package -f -M "$manifest" -I "$androidJar" -S "$resourceDirectory" -m -J "./$outputDirectory"
printf "\n"

# Compile Java source
echo "2. Finding Java source..."

rFile=$(find $outputDirectory -type f -name "*.java")
javaFiles=""
javaFiles+="$rFile "
projectFiles=$(find $projectDirectory -type f -name "*.java")
for projectFile in $projectFiles
do 
    javaFiles+="$projectFile "
done

echo "javaFiles: $javaFiles"
printf "\n"

echo "3. Compile Java source..."
classesDirectory="$outputDirectory/classes"
mkdir "$classesDirectory"
javac -source 1.6 -target 1.6 -bootclasspath /usr/java/jdk1.5.0_22/jre/lib/rt.jar $javaFiles -cp $androidJar -d $classesDirectory
printf "\n"

# DEX/Dalvik conversion
echo "4. Convert to Dalvik executable (DEX) files..."
dexFile="classes.dex"
./dx --dex --output=$dexFile $classesDirectory
if [ -f "$dexFile" ] 
then
    echo "$dexFile built successfully"
else
    echo "$dexFile did not build"
fi
printf "\n"

# Build APK
apkName="${name}.apk"
echo "5. Building $apkName"
./aapt package -v -f -M "$manifest" -S "$resourceDirectory" -I "$androidJar" -F $apkName $dexDirectory
./aapt add -f $apkName $dexFile
printf "\n"

echo "$apkName contents:"
zipinfo -1 $apkName
printf "\n"

echo "Finished"

Phaedra running on a HTC Hero

and here's Phaedra, it runs and you can browse mercury:// addresses, but there's some ui glitches to fix:

phaedra.apk


© 2019 - 2021 ÖLAB
Part of a webring
view in Gemini