- Update to Android 1.5 SDK

- Fix RouterContext problem
This commit is contained in:
zzz
2009-07-03 22:13:18 +00:00
parent 7972c0c862
commit 2e5caac8bf
5 changed files with 290 additions and 240 deletions

View File

@ -4,6 +4,8 @@
android:versionCode="1" android:versionCode="1"
android:versionName="1.0.0"> android:versionName="1.0.0">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<!-- 3 = 1.5, 2 = 1.1, 1 = 1.0; would probably work with 1 but don't have a 1.0 SDK to test against -->
<uses-sdk android:minSdkVersion="2" />
<application android:label="@string/app_name"> <application android:label="@string/app_name">
<activity android:name=".I2PAndroid" <activity android:name=".I2PAndroid"
android:label="@string/app_name" android:label="@string/app_name"

View File

@ -1,18 +1,25 @@
These instructions are for the 1.5 SDK.
The build file is not compatible with the 1.1 SDK any more.
#Unzip the android SDK in ../../ #Unzip the android SDK in ../../
#So then the android tools will be in ../../android-sdk-linux_x86-1.1_r1/tools/ #So then the android tools will be in ../../android-sdk-linux_x86-1.5_r2/tools/
#then build the android apk file: #then build the android apk file:
ant ant debug
# Create the android 1.5 virtual device
# (don't make a custom hardware profile)
../../android-sdk-linux_x86-1.5_r2/tools/android create avd --name i2p --target 2
#then run the emulator: #then run the emulator:
../../android-sdk-linux_x86-1.1_r1/tools/emulator & ../../android-sdk-linux_x86-1.5_r2/tools/emulator -avd i2p &
#then wait a couple minutes until the emulator is up #then wait a couple minutes until the emulator is up
#then install the I2P app #then install the I2P app
ant install ant install
#then run the debugger #then run the debugger
../../android-sdk-linux_x86-1.1_r1/tools/ddms & ../../android-sdk-linux_x86-1.5_r2/tools/ddms &
#to rebuild and reinstall to emulator: #to rebuild and reinstall to emulator:
ant reinstall ant reinstall

View File

@ -1,165 +1,76 @@
<?xml version="1.0" ?> <?xml version="1.0" encoding="UTF-8"?>
<project name="I2PAndroid" default="debug"> <project name=".I2PAndroid" default="help">
<!-- SDK Locations -->
<property name="sdk-folder" value="../../android-sdk-linux_x86-1.1_r1" />
<property name="android-tools" value="../../android-sdk-linux_x86-1.1_r1/tools" />
<!-- Application Package Name --> <!-- The local.properties file is created and updated by the 'android' tool.
<property name="application-package" value="net.i2p.router" /> It contain the path to the SDK. It should *NOT* be checked in in Version
Control Systems. -->
<property file="local.properties"/>
<!-- The intermediates directory --> <!-- The build.properties file can be created by you and is never touched
<!-- Eclipse uses "bin" for its own output, so we do the same. --> by the 'android' tool. This is the place to change some of the default property values
<property name="outdir" value="bin" /> used by the Ant rules.
Here are some properties you may want to change/update:
<!-- ************************************************************************************* --> application-package
<!-- No user servicable parts below. --> the name of your application package as defined in the manifest. Used by the
'uninstall' rule.
source-folder
the name of the source folder. Default is 'src'.
out-folder
the name of the output folder. Default is 'bin'.
<property name="android-framework" value="${android-tools}/lib/framework.aidl" /> Properties related to the SDK location or the project target should be updated
using the 'android' tool with the 'update' action.
<!-- Input directories --> This file is an integral part of the build system for your application and
<property name="resource-dir" value="res" /> should be checked in in Version Control Systems.
<property name="asset-dir" value="assets" />
<property name="srcdir" value="src" />
<condition property="srcdir-ospath"
value="${basedir}\${srcdir}"
else="${basedir}/${srcdir}" >
<os family="windows"/>
</condition>
<property name="external-libs" value="libs" /> -->
<condition property="external-libs-ospath" <property file="build.properties"/>
value="${basedir}\${external-libs}"
else="${basedir}/${external-libs}" >
<os family="windows"/>
</condition>
<!-- Output directories --> <!-- The default.properties file is created and updated by the 'android' tool, as well
<property name="outdir-classes" value="${outdir}/classes" /> as ADT.
<condition property="outdir-classes-ospath" This file is an integral part of the build system for your application and
value="${basedir}\${outdir-classes}" should be checked in in Version Control Systems. -->
else="${basedir}/${outdir-classes}" > <property file="default.properties"/>
<os family="windows"/>
</condition>
<!-- Create R.java in the source directory --> <!-- Custom Android task to deal with the project target, and import the proper rules.
<property name="outdir-r" value="src" /> This requires ant 1.6.0 or above. -->
<path id="android.antlibs">
<pathelement path="${sdk-location}/tools/lib/anttasks.jar" />
<pathelement path="${sdk-location}/tools/lib/sdklib.jar" />
<pathelement path="${sdk-location}/tools/lib/androidprefs.jar" />
<pathelement path="${sdk-location}/tools/lib/apkbuilder.jar" />
<pathelement path="${sdk-location}/tools/lib/jarutils.jar" />
</path>
<!-- Intermediate files --> <taskdef name="setup"
<property name="dex-file" value="classes.dex" /> classname="com.android.ant.SetupTask"
<property name="intermediate-dex" value="${outdir}/${dex-file}" /> classpathref="android.antlibs"/>
<condition property="intermediate-dex-ospath"
value="${basedir}\${intermediate-dex}"
else="${basedir}/${intermediate-dex}" >
<os family="windows"/>
</condition>
<!-- The final package file to generate --> <!-- Execute the Android Setup task that will setup some properties specific to the target,
<property name="resources-package" value="${outdir}/${ant.project.name}.ap_" /> and import the rules files.
<condition property="resources-package-ospath" To customize the rules, copy/paste them below the task, and disable import by setting
value="${base`....${resources-package}" the import attribute to false:
else="${basedir}/${resources-package}" > <setup import="false" />
<os family="windows"/>
</condition>
<property name="out-debug-package" value="${outdir}/${ant.project.name}-debug.apk" /> This will ensure that the properties are setup correctly but that your customized
<condition property="out-debug-package-ospath" targets are used.
value="${basedir}\${out-debug-package}" -->
else="${basedir}/${out-debug-package}" > <setup import="false" />
<os family="windows"/>
</condition>
<property name="out-unsigned-package" value="${outdir}/${ant.project.name}-unsigned.apk" /> <!--
<condition property="out-unsigned-package-ospath" ================================================================================
value="${basedir}\${out-unsigned-package}" New I2P rules
else="${basedir}/${out-unsigned-package}" > ================================================================================
<os family="windows"/> -->
</condition>
<!-- Tools -->
<condition property="aapt" value="${android-tools}/aapt.exe" else="${android-tools}/aapt" >
<os family="windows"/>
</condition>
<condition property="aidl" value="${android-tools}/aidl.exe" else="${android-tools}/aidl" >
<os family="windows"/>
</condition>
<condition property="adb" value="${android-tools}/adb.exe" else="${android-tools}/adb" >
<os family="windows"/>
</condition>
<condition property="dx" value="${android-tools}/dx.bat" else="${android-tools}/dx" >
<os family="windows"/>
</condition>
<condition property="apk-builder" value="${android-tools}/apkbuilder.bat" else="${android-tools}/apkbuilder" >
<os family="windows"/>
</condition>
<property name="android-jar" value="${sdk-folder}/android.jar" />
<!-- Rules -->
<!-- Create the output directories if they don't exist yet. -->
<target name="dirs">
<echo>Creating output directories if needed...</echo>
<mkdir dir="${outdir}" />
<mkdir dir="${outdir-classes}" />
<mkdir dir="${external-libs}" />
</target>
<target name="clean">
<delete dir="${outdir}" />
<delete dir="${external-libs}" />
<delete dir="tmp/" />
<delete dir="res/drawable/" />
<delete file="res/raw/blocklist_txt" />
<delete file="${outdir-r}/net/i2p/router/R.java" />
</target>
<!-- Generate the R.java file for this project's resources. -->
<target name="resource-src" depends="dirs">
<echo>Generating R.java / Manifest.java from the resources...</echo>
<exec executable="${aapt}" failonerror="true">
<arg value="package" />
<arg value="-m" />
<arg value="-J" />
<arg value="${outdir-r}" />
<arg value="-M" />
<arg value="AndroidManifest.xml" />
<arg value="-S" />
<arg value="${resource-dir}" />
<arg value="-I" />
<arg value="${android-jar}" />
</exec>
</target>
<!-- Generate java classes from .aidl files. -->
<target name="aidl" depends="dirs">
<echo>Compiling aidl files into Java classes...</echo>
<apply executable="${aidl}" failonerror="true">
<arg value="-p${android-framework}" />
<arg value="-I${srcdir}" />
<fileset dir="${srcdir}">
<include name="**/*.aidl"/>
</fileset>
</apply>
</target>
<!-- Compile this project's .java files into .class files. -->
<target name="compile" depends="buildrouter, dirs, resource-src, aidl">
<javac encoding="ascii" target="1.5" debug="true" extdirs=""
srcdir="."
destdir="${outdir-classes}"
bootclasspath="${android-jar}">
<classpath>
<fileset dir="${external-libs}" includes="*.jar"/>
</classpath>
</javac>
</target>
<target name="buildrouter" depends="dirs" > <target name="buildrouter" depends="dirs" >
<!-- build router and core --> <!-- build router and core -->
<ant dir=".." target="buildrouter" /> <ant dir=".." target="buildrouter" />
<!-- router --> <!-- router -->
<copy file="../build/router.jar" todir="${external-libs}" /> <copy file="../build/router.jar" todir="${external-libs-folder}" />
<!-- core --> <!-- core -->
<mkdir dir="tmp" /> <mkdir dir="tmp" />
@ -168,7 +79,7 @@
<!-- org.bouncycastle.crypto already in android <!-- org.bouncycastle.crypto already in android
but we need a little trickery because our HMac is incompatible... but we need a little trickery because our HMac is incompatible...
and the libs aren't in the SDK to compile against??? --> and the libs aren't in the SDK to compile against??? -->
<jar destfile="${external-libs}/crypto.jar" > <jar destfile="${external-libs-folder}/crypto.jar" >
<fileset dir="tmp/" > <fileset dir="tmp/" >
<include name="org/bouncycastle/crypto/Digest.class" /> <include name="org/bouncycastle/crypto/Digest.class" />
<include name="org/bouncycastle/crypto/Mac.class" /> <include name="org/bouncycastle/crypto/Mac.class" />
@ -190,7 +101,7 @@
--> -->
<delete file="tmp/org/bouncycastle/" /> <delete file="tmp/org/bouncycastle/" />
<!-- lots of unneeded stuff could be deleted here --> <!-- lots of unneeded stuff could be deleted here -->
<jar destfile="${external-libs}/i2p.jar" basedir="tmp/" /> <jar destfile="${external-libs-folder}/i2p.jar" basedir="tmp/" />
<!-- some resources --> <!-- some resources -->
<mkdir dir="res/drawable/" /> <mkdir dir="res/drawable/" />
@ -199,104 +110,199 @@
</target> </target>
<target name="hackcleanup"> <target name="hackcleanup">
<delete file="${external-libs}/crypto.jar" /> <delete file="${external-libs-folder}/crypto.jar" />
</target> </target>
<!-- Convert this project's .class files into .dex files. --> <!--
<target name="dex" depends="compile, hackcleanup"> ================================================================================
<echo>Converting compiled files and external libraries into ${outdir}/${dex-file}...</echo> From here down copied from SDK platforms/android-1.1/templates/android_rules.xml
<apply executable="${dx}" failonerror="true" parallel="true"> and then modified
<!-- this is a bad sign that we need this --> ================================================================================
<arg value="-JXmx256m" /> -->
<arg value="--dex" />
<arg value="--output=${intermediate-dex-ospath}" /> <!--
<arg path="${outdir-classes-ospath}" /> This rules file is meant to be imported by the custom Ant task:
<fileset dir="${external-libs}" includes="*.jar"/> com.android.ant.AndroidInitTask
The following properties are put in place by the importing task:
android-jar, android-aidl, aapt, aidl, and dx
Additionnaly, the task sets up the following classpath reference:
android.target.classpath
This is used by the compiler task as the boot classpath.
-->
<!-- Custom tasks -->
<taskdef name="aaptexec"
classname="com.android.ant.AaptExecLoopTask"
classpathref="android.antlibs"/>
<taskdef name="apkbuilder"
classname="com.android.ant.ApkBuilderTask"
classpathref="android.antlibs"/>
<!-- Properties -->
<property name="android-tools" value="${sdk-location}/tools" />
<!-- Input directories -->
<property name="source-folder" value="src" />
<property name="gen-folder" value="gen" />
<property name="resource-folder" value="res" />
<property name="asset-folder" value="assets" />
<property name="source-location" value="${basedir}/${source-folder}" />
<!-- folder for the 3rd party java libraries -->
<property name="external-libs-folder" value="libs" />
<!-- folder for the native libraries -->
<property name="native-libs-folder" value="libs" />
<!-- Output directories -->
<property name="gen-folder" value="gen" />
<property name="out-folder" value="bin" />
<property name="out-classes" value="${out-folder}/classes" />
<property name="out-classes-location" value="${basedir}/${out-classes}"/>
<!-- out folders for a parent project if this project is an instrumentation project -->
<property name="main-out-folder" value="../${out-folder}" />
<property name="main-out-classes" value="${main-out-folder}/classes"/>
<!-- Intermediate files -->
<property name="dex-file" value="classes.dex" />
<property name="intermediate-dex" value="${out-folder}/${dex-file}" />
<!-- dx does not properly support incorrect / or \ based on the platform
and Ant cannot convert them because the parameter is not a valid path.
Because of this we have to compute different paths depending on the platform. -->
<condition property="intermediate-dex-location"
value="${basedir}\${intermediate-dex}"
else="${basedir}/${intermediate-dex}" >
<os family="windows"/>
</condition>
<!-- The final package file to generate -->
<property name="out-debug-package" value="${out-folder}/${ant.project.name}-debug.apk"/>
<!-- Tools -->
<condition property="exe" value=".exe" else=""><os family="windows"/></condition>
<property name="adb" value="${android-tools}/adb${exe}"/>
<!-- rules -->
<!-- Create the output directories if they don't exist yet. -->
<target name="dirs">
<echo>Creating output directories if needed...</echo>
<mkdir dir="${resource-folder}" />
<mkdir dir="${external-libs-folder}" />
<mkdir dir="${gen-folder}" />
<mkdir dir="${out-folder}" />
<mkdir dir="${out-classes}" />
</target>
<!-- Generate the R.java file for this project's resources. -->
<target name="resource-src" depends="dirs">
<echo>Generating R.java / Manifest.java from the resources...</echo>
<exec executable="${aapt}" failonerror="true">
<arg value="package" />
<arg value="-m" />
<arg value="-J" />
<arg path="${gen-folder}" />
<arg value="-M" />
<arg path="AndroidManifest.xml" />
<arg value="-S" />
<arg path="${resource-folder}" />
<arg value="-I" />
<arg path="${android-jar}" />
</exec>
</target>
<!-- Generate java classes from .aidl files. -->
<target name="aidl" depends="dirs">
<echo>Compiling aidl files into Java classes...</echo>
<apply executable="${aidl}" failonerror="true">
<arg value="-p${android-aidl}" />
<arg value="-I${source-folder}" />
<arg value="-o${gen-folder}" />
<fileset dir="${source-folder}">
<include name="**/*.aidl"/>
</fileset>
</apply> </apply>
</target> </target>
<!-- Put the project's resources into the output package file. --> <!-- Compile this project's .java files into .class files. -->
<target name="package-res-and-assets"> <!-- I2P add buildrouter -->
<echo>Packaging resources and assets...</echo> <target name="compile" depends="buildrouter, resource-src, aidl">
<exec executable="${aapt}" failonerror="true"> <javac encoding="ascii" target="1.5" debug="true" extdirs=""
<arg value="package" /> destdir="${out-classes}"
<arg value="-f" /> bootclasspathref="android.target.classpath">
<arg value="-M" /> <src path="${source-folder}" />
<arg value="AndroidManifest.xml" /> <src path="${gen-folder}" />
<arg value="-S" /> <classpath>
<arg value="${resource-dir}" /> <fileset dir="${external-libs-folder}" includes="*.jar"/>
<arg value="-A" /> <pathelement path="${main-out-classes}"/>
<arg value="${asset-dir}" /> </classpath>
<arg value="-I" /> </javac>
<arg value="${android-jar}" />
<arg value="-F" />
<arg value="${resources-package}" />
</exec>
</target> </target>
<!-- Same as package-res-and-assets, but without "-A ${asset-dir}" --> <!-- Convert this project's .class files into .dex files. -->
<target name="package-res-no-assets"> <!-- I2P add hackcleanup -->
<echo>Packaging resources...</echo> <target name="dex" depends="compile, hackcleanup">
<exec executable="${aapt}" failonerror="true"> <echo>Converting compiled files and external libraries into ${out-folder}/${dex-file}...</echo>
<arg value="package" /> <apply executable="${dx}" failonerror="true" parallel="true">
<arg value="-f" /> <!-- I2P this is a bad sign that we need this -->
<arg value="-M" /> <arg value="-JXmx256m" />
<arg value="AndroidManifest.xml" /> <arg value="--dex" />
<arg value="-S" /> <arg value="--output=${intermediate-dex-location}" />
<arg value="${resource-dir}" /> <arg path="${out-classes-location}" />
<!-- No assets directory --> <fileset dir="${external-libs-folder}" includes="*.jar"/>
<arg value="-I" /> </apply>
<arg value="${android-jar}" />
<arg value="-F" />
<arg value="${resources-package}" />
</exec>
</target> </target>
<!-- Invoke the proper target depending on whether or not <!-- Put the project's resources into the output package file
an assets directory is present. --> This actually can create multiple resource package in case
<!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument Some custom apk with specific configuration have been
only when the assets dir exists. --> declared in default.properties.
<target name="package-res"> -->
<available file="${asset-dir}" type="dir" <target name="package-resources">
property="res-target" value="and-assets" /> <echo>Packaging resources</echo>
<property name="res-target" value="no-assets" /> <aaptexec executable="${aapt}"
<antcall target="package-res-${res-target}" /> command="package"
manifest="AndroidManifest.xml"
resources="${resource-folder}"
assets="${asset-folder}"
androidjar="${android-jar}"
outfolder="${out-folder}"
basename="${ant.project.name}" />
</target> </target>
<!-- Package the application and sign it with a debug key. <!-- Package the application and sign it with a debug key.
This is the default target when building. It is used for debug. --> This is the default target when building. It is used for debug. -->
<target name="debug" depends="dex, package-res"> <target name="debug" depends="dex, package-resources">
<echo>Packaging ${out-debug-package}, and signing it with a debug key...</echo> <apkbuilder
<exec executable="${apk-builder}" failonerror="true"> outfolder="${out-folder}"
<arg value="${out-debug-package-ospath}" /> basename="${ant.project.name}"
<arg value="-z" /> signed="true"
<arg value="${resources-package-ospath}" /> verbose="false">
<arg value="-f" /> <file path="${intermediate-dex}" />
<arg value="${intermediate-dex-ospath}" /> <sourcefolder path="${source-folder}" />
<arg value="-rf" /> <jarfolder path="${external-libs-folder}" />
<arg value="${srcdir-ospath}" /> <nativefolder path="${native-libs-folder}" />
<arg value="-rj" /> </apkbuilder>
<arg value="${external-libs-ospath}" />
</exec>
</target> </target>
<!-- Package the application without signing it. <!-- Package the application without signing it.
This allows for the application to be signed later with an official publishing key. --> This allows for the application to be signed later with an official publishing key. -->
<target name="release" depends="dex, package-res"> <target name="release" depends="dex, package-resources">
<echo>Packaging ${out-unsigned-package} for release...</echo> <apkbuilder
<exec executable="${apk-builder}" failonerror="true"> outfolder="${out-folder}"
<arg value="${out-unsigned-package-ospath}" /> basename="${ant.project.name}"
<arg value="-u" /> signed="false"
<arg value="-z" /> verbose="false">
<arg value="${resources-package-ospath}" /> <file path="${intermediate-dex}" />
<arg value="-f" /> <sourcefolder path="${source-folder}" />
<arg value="${intermediate-dex-ospath}" /> <jarfolder path="${external-libs-folder}" />
<arg value="-rf" /> <nativefolder path="${native-libs-folder}" />
<arg value="${srcdir-ospath}" /> </apkbuilder>
<arg value="-rj" /> <echo>All generated packages need to be signed with jarsigner before they are published.</echo>
<arg value="${external-libs-ospath}" />
</exec>
<echo>It will need to be signed with jarsigner before being published.</echo>
</target> </target>
<!-- Install the package on the default emulator --> <!-- Install the package on the default emulator -->
@ -304,7 +310,7 @@
<echo>Installing ${out-debug-package} onto default emulator...</echo> <echo>Installing ${out-debug-package} onto default emulator...</echo>
<exec executable="${adb}" failonerror="true"> <exec executable="${adb}" failonerror="true">
<arg value="install" /> <arg value="install" />
<arg value="${out-debug-package}" /> <arg path="${out-debug-package}" />
</exec> </exec>
</target> </target>
@ -313,7 +319,7 @@
<exec executable="${adb}" failonerror="true"> <exec executable="${adb}" failonerror="true">
<arg value="install" /> <arg value="install" />
<arg value="-r" /> <arg value="-r" />
<arg value="${out-debug-package}" /> <arg path="${out-debug-package}" />
</exec> </exec>
</target> </target>
@ -322,8 +328,25 @@
<echo>Uninstalling ${application-package} from the default emulator...</echo> <echo>Uninstalling ${application-package} from the default emulator...</echo>
<exec executable="${adb}" failonerror="true"> <exec executable="${adb}" failonerror="true">
<arg value="uninstall" /> <arg value="uninstall" />
<arg value="${application-package}" /> <arg path="${application-package}" />
</exec> </exec>
</target> </target>
<target name="help">
<!-- displays starts at col 13
|13 80| -->
<echo>Android Ant Build. Available targets:</echo>
<echo> help: Displays this help.</echo>
<echo> debug: Builds the application and sign it with a debug key.</echo>
<echo> release: Builds the application. The generated apk file must be</echo>
<echo> signed before it is published.</echo>
<echo> install: Installs the debug package onto a running emulator or</echo>
<echo> device. This can only be used if the application has </echo>
<echo> not yet been installed.</echo>
<echo> reinstall: Installs the debug package on a running emulator or</echo>
<echo> device that already has the application.</echo>
<echo> The signatures must match.</echo>
<echo> uninstall: uninstall the application from a running emulator or</echo>
<echo> device.</echo>
</target>
</project> </project>

View File

@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-2

View File

@ -10,10 +10,10 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import net.i2p.router.Router; import net.i2p.router.Router;
import net.i2p.router.RouterLaunch; import net.i2p.router.RouterLaunch;
import net.i2p.router.web.ContextHelper;
// import net.i2p.util.NativeBigInteger; // import net.i2p.util.NativeBigInteger;
public class I2PAndroid extends Activity public class I2PAndroid extends Activity
@ -66,8 +66,15 @@ public class I2PAndroid extends Activity
{ {
System.err.println("onStop called"); System.err.println("onStop called");
super.onStop(); super.onStop();
// from routerconsole ContextHelper
List contexts = RouterContext.listContexts();
if ( (contexts == null) || (contexts.size() <= 0) )
throw new IllegalStateException("No contexts. This is usually because the router is either starting up or shutting down.");
RouterContext ctx = (RouterContext)contexts.get(0);
// shutdown() doesn't return so use shutdownGracefully() // shutdown() doesn't return so use shutdownGracefully()
ContextHelper.getContext(null).router().shutdownGracefully(Router.EXIT_HARD); ctx.router().shutdownGracefully(Router.EXIT_HARD);
System.err.println("shutdown complete"); System.err.println("shutdown complete");
} }