From 7e84451ac3d65138615bf8c3e440095037446c19 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sun, 5 Jun 2011 22:38:35 +0000 Subject: [PATCH] Android: - Import the main_rules file and remove the copied rules - Set the version code and name in the apk badging - Build target is 8 to allow SD install, MIN-SDK is still 3 - Fix NPE on new install - Remove some debug code from NBigI --- android/AndroidManifest.xml | 8 +- android/README.txt | 7 +- android/build.xml | 763 +----------------- android/default.properties | 2 +- android/scripts/setversion.sh | 2 + android/src/net/i2p/router/I2PAndroid.java | 25 +- .../src/net/i2p/util/NativeBigInteger.java | 11 +- 7 files changed, 72 insertions(+), 746 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index a66d987ae..98ffe9d89 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -1,12 +1,16 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.i2p.router" - android:versionCode="1" - android:versionName="1.0.0"> + android.versionCode="0" + android.versionName="0.0.0" + android:installLocation="preferExternal" + > <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 --> <!-- 3 required for NDK --> <uses-sdk android:minSdkVersion="3" /> + <application android:label="@string/app_name"> <activity android:name="I2PAndroid" android:label="@string/app_name" diff --git a/android/README.txt b/android/README.txt index fe84055d1..ff5b1f2d6 100644 --- a/android/README.txt +++ b/android/README.txt @@ -36,6 +36,11 @@ SDK Platform-tools Version 5, June 2011. #then run the emulator: ../../android-sdk-linux_86/tools/emulator -avd i2p & +# or to talk to a real phone in debug mode: +adb kill-server +sudo adb start-server +adb devices + #then wait a couple minutes until the emulator is up #then install the I2P app ant install @@ -43,7 +48,7 @@ ant install #then run the debugger ../../android-sdk-linux_86/tools/ddms & -#to rebuild and reinstall to emulator: +#to rebuild and reinstall to emulator or phone: ant reinstall # Now click on the I2P icon on your phone! diff --git a/android/build.xml b/android/build.xml index 4be56043a..37b241ea8 100644 --- a/android/build.xml +++ b/android/build.xml @@ -67,14 +67,25 @@ This will ensure that the properties are setup correctly but that your customized targets are used. --> - <setup import="false" /> + <setup import="true" /> + <echo>Ignore warning about SDK version</echo> <!-- ================================================================================ New I2P rules ================================================================================ --> + <!-- overrides of those in main_rules.xml --> + + <target name="-pre-build" depends="copy-i2p-resources, incrementBuild" /> + + <target name="-pre-compile" depends="buildrouter" /> + + <target name="-post-compile" depends="hackcleanup, jbigi" /> + + <!-- new rules --> + <target name="buildrouter" depends="-dirs" > <!-- build router and core --> <ant dir=".." target="buildrouter" /> @@ -135,6 +146,8 @@ <arg value="-c" /> <arg value="scripts/setversion.sh" /> </exec> + <!-- this loads my.version.code and my.version.name --> + <property file="scripts/version.properties" /> </target> <!-- install now does both --> @@ -147,6 +160,7 @@ <delete dir="jni/build/" verbose="${verbose}" /> <delete file="jni/libjbigi.so" verbose="${verbose}" /> <delete file="scripts/build.number" verbose="${verbose}" /> + <delete file="scripts/version.properties" verbose="${verbose}" /> </target> <!-- @@ -156,486 +170,14 @@ ================================================================================ --> + <!-- not necessary to copy if setup import="true" --> - <!-- - This rules file is meant to be imported by the custom Ant task: - com.android.ant.SetupTask - - 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="aapt" - classname="com.android.ant.AaptExecLoopTask" - classpathref="android.antlibs" /> - - <taskdef name="aidl" - classname="com.android.ant.AidlExecTask" - classpathref="android.antlibs" /> - - <taskdef name="renderscript" - classname="com.android.ant.RenderScriptTask" - classpathref="android.antlibs" /> - - <taskdef name="apkbuilder" - classname="com.android.ant.ApkBuilderTask" - classpathref="android.antlibs" /> - - <taskdef name="xpath" - classname="com.android.ant.XPathTask" - classpathref="android.antlibs" /> - - <taskdef name="if" - classname="com.android.ant.IfElseTask" - classpathref="android.antlibs" /> - - <!-- Properties --> - - <!-- Tells adb which device to target. You can change this from the command line - by invoking "ant -Dadb.device.arg=-d" for device "ant -Dadb.device.arg=-e" for - the emulator. --> - <property name="adb.device.arg" value="" /> - - <property name="android.tools.dir" location="${sdk.dir}/tools" /> - <property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" /> - <!-- Name of the application package extracted from manifest file --> - <xpath input="AndroidManifest.xml" expression="/manifest/@package" - output="manifest.package" /> - <!-- Value of the hasCode attribute (Application node) extracted from manifest file --> - <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:hasCode" - output="manifest.hasCode" default="true"/> - - <!-- Input directories --> - <property name="source.dir" value="src" /> - <property name="source.absolute.dir" location="${source.dir}" /> - <property name="gen.dir" value="gen" /> - <property name="gen.absolute.dir" location="${gen.dir}" /> - <property name="resource.dir" value="res" /> - <property name="resource.absolute.dir" location="${resource.dir}" /> - <property name="asset.dir" value="assets" /> - <property name="asset.absolute.dir" location="${asset.dir}" /> - - <!-- Directory for the third party java libraries --> - <property name="jar.libs.dir" value="libs" /> - <property name="jar.libs.absolute.dir" location="${jar.libs.dir}" /> - <!-- create a path with all the jar files, from the main project and the - libraries --> - <path id="jar.libs.ref"> - <fileset dir="${jar.libs.absolute.dir}" includes="*.jar" /> - <path refid="project.libraries.jars" /> - </path> - - <!-- Directory for the native libraries --> - <property name="native.libs.dir" value="libs" /> - <property name="native.libs.absolute.dir" location="${native.libs.dir}" /> - - <!-- Output directories --> - <property name="out.dir" value="bin" /> - <property name="out.absolute.dir" location="${out.dir}" /> - <property name="out.classes.dir" value="${out.absolute.dir}/classes" /> - <property name="out.classes.absolute.dir" location="${out.classes.dir}" /> - - <!-- Intermediate files --> - <property name="dex.file.name" value="classes.dex" /> - <property name="intermediate.dex.file" - location="${out.absolute.dir}/${dex.file.name}" /> - <property name="resource.package.file.name" - value="${ant.project.name}.ap_" /> - - <!-- The final package file to generate - These can be overridden by setting them earlier to - different values --> - <property name="out.debug.unaligned.file" - location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" /> - <property name="out.debug.file" - location="${out.absolute.dir}/${ant.project.name}-debug.apk" /> - - <property name="out.unsigned.file.name" - value="${ant.project.name}-unsigned.apk" /> - <property name="out.unsigned.file" - location="${out.absolute.dir}/${out.unsigned.file.name}" /> - - <property name="out.unaligned.file.name" - value="${ant.project.name}-unaligned.apk" /> - <property name="out.unaligned.file" - location="${out.absolute.dir}/${out.unaligned.file.name}" /> - - <property name="out.release.file.name" - value="${ant.project.name}-release.apk" /> - <property name="out.release.file" - location="${out.absolute.dir}/${out.release.file.name}" /> - - <!-- set some properties used for filtering/override. If those weren't defined - before, then this will create them with empty values, which are then ignored - by the custom tasks receiving them. --> - <property name="version.code" value="" /> - <property name="aapt.resource.filter" value="" /> - <property name="filter.abi" value="" /> - - <!-- compilation options --> - <property name="java.encoding" value="UTF-8" /> - <property name="java.target" value="1.5" /> - <property name="java.source" value="1.5" /> - - <!-- Verbosity --> - <property name="verbose" value="false" /> - <!-- This is needed by emma as it uses multilevel verbosity instead of simple 'true' or 'false' - The property 'verbosity' is not user configurable and depends exclusively on 'verbose' - value.--> - <condition property="verbosity" value="verbose" else="quiet"> - <istrue value="${verbose}" /> - </condition> - <!-- This is needed to switch verbosity of zipalign. Depends exclusively on 'verbose' - --> - <condition property="v.option" value="-v" else=""> - <istrue value="${verbose}" /> - </condition> - <!-- This is needed to switch verbosity of dx. Depends exclusively on 'verbose' --> - <condition property="verbose.option" value="--verbose" else=""> - <istrue value="${verbose}" /> - </condition> - - <!-- properties for signing in release mode --> - <condition property="has.keystore"> - <and> - <isset property="key.store" /> - <length string="${key.store}" when="greater" length="0" /> - <isset property="key.alias" /> - </and> - </condition> - <condition property="has.password"> - <and> - <isset property="has.keystore" /> - <isset property="key.store.password" /> - <isset property="key.alias.password" /> - </and> - </condition> - - <!-- Tools --> - <condition property="exe" value=".exe" else=""><os family="windows" /></condition> - <property name="adb" location="${android.platform.tools.dir}/adb${exe}" /> - <property name="zipalign" location="${android.tools.dir}/zipalign${exe}" /> - - <!-- Emma configuration --> - <property name="emma.dir" value="${sdk.dir}/tools/lib" /> - <path id="emma.lib"> - <pathelement location="${emma.dir}/emma.jar" /> - <pathelement location="${emma.dir}/emma_ant.jar" /> - </path> - <taskdef resource="emma_ant.properties" classpathref="emma.lib" /> - <!-- End of emma configuration --> - - <!-- Macros --> - - <!-- Configurable macro, which allows to pass as parameters output directory, - output dex filename and external libraries to dex (optional) --> - <macrodef name="dex-helper"> - <element name="external-libs" optional="yes" /> - <element name="extra-parameters" optional="yes" /> - <sequential> - <!-- sets the primary input for dex. If a pre-dex task sets it to - something else this has no effect --> - <property name="out.dex.input.absolute.dir" value="${out.classes.absolute.dir}" /> - - <!-- set the secondary dx input: the project (and library) jar files - If a pre-dex task sets it to something else this has no effect --> - <if> - <condition> - <isreference refid="out.dex.jar.input.ref" /> - </condition> - <else> - <path id="out.dex.jar.input.ref"> - <path refid="jar.libs.ref" /> - </path> - </else> - </if> - - <echo>Converting compiled files and external libraries into ${intermediate.dex.file}...</echo> - <apply executable="${dx}" failonerror="true" parallel="true"> - <arg value="--dex" /> - <arg value="--output=${intermediate.dex.file}" /> - <extra-parameters /> - <arg line="${verbose.option}" /> - <arg path="${out.dex.input.absolute.dir}" /> - <path refid="out.dex.jar.input.ref" /> - <external-libs /> - </apply> - </sequential> - </macrodef> - - <!-- This is macro that enable passing variable list of external jar files to ApkBuilder - Example of use: - <package-helper output.filepath="/path/to/foo.apk"> - <extra-jars> - <jarfolder path="my_jars" /> - <jarfile path="foo/bar.jar" /> - <jarfolder path="your_jars" /> - </extra-jars> - </package-helper> --> - <macrodef name="package-helper"> - <attribute name="output.filepath" /> - <element name="extra-jars" optional="yes" /> - <sequential> - <apkbuilder - outfolder="${out.absolute.dir}" - resourcefile="${resource.package.file.name}" - apkfilepath="@{output.filepath}" - debugpackaging="${build.packaging.debug}" - debugsigning="${build.signing.debug}" - abifilter="${filter.abi}" - verbose="${verbose}" - hascode="${manifest.hasCode}"> - <dex path="${intermediate.dex.file}"/> - <sourcefolder path="${source.absolute.dir}"/> - <sourcefolder refid="project.libraries.src"/> - <jarfolder path="${jar.libs.absolute.dir}" /> - <jarfolder refid="project.libraries.libs" /> - <nativefolder path="${native.libs.absolute.dir}" /> - <nativefolder refid="project.libraries.libs" /> - <extra-jars/> - </apkbuilder> - </sequential> - </macrodef> - - <!-- This is macro which zipaligns in.package and outputs it to out.package. Used by targets - debug, -debug-with-emma and release.--> - <macrodef name="zipalign-helper"> - <attribute name="in.package" /> - <attribute name="out.package" /> - <sequential> - <echo>Running zip align on final apk...</echo> - <exec executable="${zipalign}" failonerror="true"> - <arg line="${v.option}" /> - <arg value="-f" /> - <arg value="4" /> - <arg path="@{in.package}" /> - <arg path="@{out.package}" /> - </exec> - </sequential> - </macrodef> - - <!-- This is macro used only for sharing code among two targets, -install and - -install-with-emma which do exactly the same but differ in dependencies --> - <macrodef name="install-helper"> - <sequential> - <echo>Installing ${out.debug.file} onto default emulator or device...</echo> - <exec executable="${adb}" failonerror="true"> - <arg line="${adb.device.arg}" /> - <arg value="install" /> - <arg value="-r" /> - <arg path="${out.debug.file}" /> - </exec> - </sequential> - </macrodef> - - <!-- Rules --> - - <!-- Creates the output directories if they don't exist yet. --> - <target name="-dirs"> - <echo>Creating output directories if needed...</echo> - <mkdir dir="${resource.absolute.dir}" /> - <mkdir dir="${jar.libs.absolute.dir}" /> - <mkdir dir="${out.absolute.dir}" /> - <if condition="${manifest.hasCode}"> - <then> - <mkdir dir="${gen.absolute.dir}" /> - <mkdir dir="${out.classes.absolute.dir}" /> - </then> - </if> - </target> - - <!-- empty default pre-build target. Create a similar target in - your build.xml and it'll be called instead of this one. --> - <!-- I2P add depends --> - <target name="-pre-build" depends="copy-i2p-resources, incrementBuild" /> - - <!-- Generates the R.java file for this project's resources. --> - <target name="-resource-src" depends="-dirs"> - <if condition="${manifest.hasCode}"> - <then> - <echo>Generating R.java / Manifest.java from the resources...</echo> - <aapt executable="${aapt}" - command="package" - verbose="${verbose}" - manifest="AndroidManifest.xml" - androidjar="${android.jar}" - rfolder="${gen.absolute.dir}"> - <res path="${resource.absolute.dir}" /> - </aapt> - </then> - <else> - <echo>hasCode = false. Skipping...</echo> - </else> - </if> - </target> - <!-- Generates java classes from .aidl files. --> - <target name="-aidl" depends="-dirs"> - <if condition="${manifest.hasCode}"> - <then> - <echo>Compiling aidl files into Java classes...</echo> - <aidl executable="${aidl}" framework="${android.aidl}" - genFolder="${gen.absolute.dir}"> - <source path="${source.absolute.dir}"/> - <source refid="project.libraries.src"/> - </aidl> - </then> - <else> - <echo>hasCode = false. Skipping...</echo> - </else> - </if> - </target> - - <!-- Compiles RenderScript files into Java and bytecode. --> - <target name="-renderscript" depends="-dirs"> - <if condition="${manifest.hasCode}"> - <then> - <echo>Compiling RenderScript files into Java classes and RenderScript bytecode...</echo> - <renderscript executable="${renderscript}" - framework="${android.rs}" - genFolder="${gen.absolute.dir}" - resFolder="${resource.absolute.dir}/raw"> - <source path="${source.absolute.dir}"/> - <source refid="project.libraries.src"/> - </renderscript> - </then> - <else> - <echo>hasCode = false. Skipping...</echo> - </else> - </if> - </target> - - <!-- empty default pre-compile target. Create a similar target in - your build.xml and it'll be called instead of this one. --> - <!-- I2P add depends --> - <target name="-pre-compile" depends="buildrouter" /> - - <!-- Compiles this project's .java files into .class files. --> - <target name="compile" depends="-pre-build, -aidl, -renderscript, -resource-src, -pre-compile" - description="Compiles project's .java files into .class files"> - <if condition="${manifest.hasCode}"> - <then> - <!-- If android rules are used for a test project, its classpath should include - tested project's location --> - <condition property="extensible.classpath" - value="${tested.project.absolute.dir}/bin/classes" - else="."> - <isset property="tested.project.absolute.dir" /> - </condition> - <condition property="extensible.libs.classpath" - value="${tested.project.absolute.dir}/libs" - else="${jar.libs.dir}"> - <isset property="tested.project.absolute.dir" /> - </condition> - <javac encoding="${java.encoding}" - source="${java.source}" target="${java.target}" - debug="true" extdirs="" - includeantruntime="false" - destdir="${out.classes.absolute.dir}" - bootclasspathref="android.target.classpath" - verbose="${verbose}" - classpath="${extensible.classpath}" - classpathref="jar.libs.ref"> - <src path="${source.absolute.dir}" /> - <src path="${gen.absolute.dir}" /> - <src refid="project.libraries.src" /> - <classpath> - <fileset dir="${extensible.libs.classpath}" includes="*.jar" /> - </classpath> - </javac> - </then> - <else> - <echo>hasCode = false. Skipping...</echo> - </else> - </if> - </target> - - <!-- empty default post-compile target. Create a similar target in - your build.xml and it'll be called instead of this one. --> - <!-- I2P add depends --> - <target name="-post-compile" depends="hackcleanup, jbigi" /> - - <!-- Obfuscate target - This is only active in release builds when proguard.config is defined - in default.properties. - - To replace Proguard with a different obfuscation engine: - Override the following targets in your build.xml, before the call to <setup> - -release-obfuscation-check - Check whether obfuscation should happen, and put the result in a property. - -debug-obfuscation-check - Obfuscation should not happen. Set the same property to false. - -obfuscate - ** Make sure unless="do.not.compile" is used in the target definition ** - check if the property set in -debug/release-obfuscation-check is set to true. - If true: - Perform obfuscation - Set property out.dex.input.absolute.dir to be the output of the obfuscation + <!-- + override this because the ant task com.android.ant.AaptExecLoopTask has issues: + a) it uses version.code which main_rules sets to "" and + b) it can't set versionName via the aapt task, have to use the aapt command line --> - <target name="-obfuscate" unless="do.not.compile"> - <if condition="${proguard.enabled}"> - <then> - <property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard" /> - <property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar" /> - <property name="obfuscated.jar.file" value="${obfuscate.absolute.dir}/obfuscated.jar" /> - <!-- input for dex will be proguard's output --> - <property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}" /> - - <!-- Add Proguard Tasks --> - <property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar" /> - <taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" /> - - <!-- Set the android classpath Path object into a single property. It'll be - all the jar files separated by a platform path-separator. - --> - <property name="android.libraryjars" refid="android.target.classpath"/> - <!-- Build a path object with all the jar files that must be obfuscated. - This include the project compiled source code and any 3rd party jar - files. --> - <path id="project.jars.ref"> - <pathelement location="${preobfuscate.jar.file}" /> - <path refid="jar.libs.ref" /> - </path> - <!-- Set the project jar files Path object into a single property. It'll be - all the jar files separated by a platform path-separator. - --> - <property name="project.jars" refid="project.jars.ref" /> - - <mkdir dir="${obfuscate.absolute.dir}" /> - <delete file="${preobfuscate.jar.file}"/> - <delete file="${obfuscated.jar.file}"/> - <jar basedir="${out.classes.dir}" destfile="${preobfuscate.jar.file}" /> - <proguard> - @${proguard.config} - -injars ${project.jars} - -outjars ${obfuscated.jar.file} - -libraryjars ${android.libraryjars} - -dump ${obfuscate.absolute.dir}/dump.txt - -printseeds ${obfuscate.absolute.dir}/seeds.txt - -printusage ${obfuscate.absolute.dir}/usage.txt - -printmapping ${obfuscate.absolute.dir}/mapping.txt - </proguard> - </then> - </if> - </target> - - <!-- Converts this project's .class files into .dex files --> - <target name="-dex" depends="compile, -post-compile, -obfuscate" - unless="do.not.compile"> - <if condition="${manifest.hasCode}"> - <then> - <dex-helper /> - </then> - <else> - <echo>hasCode = false. Skipping...</echo> - </else> - </if> - </target> <!-- Puts the project's resources into the output package file This actually can create multiple resource package in case @@ -644,254 +186,25 @@ --> <target name="-package-resources"> <echo>Packaging resources</echo> - <aapt executable="${aapt}" - command="package" - versioncode="${version.code}" - debug="${build.packaging.debug}" - manifest="AndroidManifest.xml" - assets="${asset.absolute.dir}" - androidjar="${android.jar}" - apkfolder="${out.absolute.dir}" - resourcefilename="${resource.package.file.name}" - resourcefilter="${aapt.resource.filter}"> - <res path="${resource.absolute.dir}" /> - <!-- <nocompress /> forces no compression on any files in assets or res/raw --> - <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw --> - </aapt> - </target> - - <!-- Packages the application and sign it with a debug key. --> - <target name="-package-debug-sign" depends="-dex, -package-resources"> - <package-helper - output.filepath="${out.debug.unaligned.file}" /> - </target> - - <!-- Packages the application without signing it. --> - <target name="-package-release" depends="-dex, -package-resources"> - <package-helper - output.filepath="${out.unsigned.file}"/> - </target> - - <target name="-compile-tested-if-test" if="tested.project.dir" unless="do.not.compile.again"> - <subant target="compile"> - <fileset dir="${tested.project.absolute.dir}" includes="build.xml" /> - </subant> - </target> - - <target name="-debug-obfuscation-check"> - <!-- proguard is never enabled in debug mode --> - <property name="proguard.enabled" value="false"/> - </target> - - <target name="-set-debug-mode" depends="-debug-obfuscation-check"> - <!-- property only set in debug mode. - Useful for if/unless attributes in target node - when using Ant before 1.8 --> - <property name="build.mode.debug" value="true"/> - - <!-- whether the build is a debug build. always set. --> - <property name="build.packaging.debug" value="true" /> - - <!-- signing mode: debug --> - <property name="build.signing.debug" value="true" /> - - </target> - - <!-- Builds debug output package, provided all the necessary files are already dexed --> - <target name="debug" depends="-set-debug-mode, -compile-tested-if-test, -package-debug-sign" - description="Builds the application and signs it with a debug key."> - <zipalign-helper in.package="${out.debug.unaligned.file}" - out.package="${out.debug.file}" /> - <echo>Debug Package: ${out.debug.file}</echo> - </target> - - <!-- called through target 'release'. Only executed if the keystore and - key alias are known but not their password. --> - <target name="-release-prompt-for-password" if="has.keystore" unless="has.password"> - <!-- Gets passwords --> - <input - message="Please enter keystore password (store:${key.store}):" - addproperty="key.store.password" /> - <input - message="Please enter password for alias '${key.alias}':" - addproperty="key.alias.password" /> - </target> - - <!-- called through target 'release'. Only executed if there's no - keystore/key alias set --> - <target name="-release-nosign" unless="has.keystore"> - <echo>No key.store and key.alias properties found in build.properties.</echo> - <echo>Please sign ${out.unsigned.file} manually</echo> - <echo>and run zipalign from the Android SDK tools.</echo> - </target> - - <target name="-release-obfuscation-check"> - <condition property="proguard.enabled" value="true" else="false"> - <and> - <isset property="build.mode.release" /> - <isset property="proguard.config" /> - </and> - </condition> - <if condition="${proguard.enabled}"> - <then> - <!-- Secondary dx input (jar files) is empty since all the - jar files will be in the obfuscated jar --> - <path id="out.dex.jar.input.ref" /> - </then> - </if> - </target> - - <target name="-set-release-mode"> - <!-- release mode is only valid if the manifest does not explicitly - set debuggable to true. default is false. - We actually store build.packaging.debug, not build.release --> - <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:debuggable" - output="build.packaging.debug" default="false"/> - - <!-- signing mode: release --> - <property name="build.signing.debug" value="false" /> - - <if condition="${build.packaging.debug}"> - <then> - <echo>*************************************************</echo> - <echo>**** Android Manifest has debuggable=true ****</echo> - <echo>**** Doing DEBUG packaging with RELEASE keys ****</echo> - <echo>*************************************************</echo> - </then> - <else> - <!-- property only set in release mode. - Useful for if/unless attributes in target node - when using Ant before 1.8 --> - <property name="build.mode.release" value="true"/> - </else> - </if> - </target> - - <!-- This runs -package-release and -release-nosign first and then runs - only if release-sign is true (set in -release-check, - called by -release-no-sign)--> - <target name="release" - depends="-set-release-mode, -release-obfuscation-check, -package-release, -release-prompt-for-password, -release-nosign" - if="has.keystore" - description="Builds the application. The generated apk file must be signed before - it is published."> - <!-- Signs the APK --> - <echo>Signing final apk...</echo> - <signjar - jar="${out.unsigned.file}" - signedjar="${out.unaligned.file}" - keystore="${key.store}" - storepass="${key.store.password}" - alias="${key.alias}" - keypass="${key.alias.password}" - verbose="${verbose}" /> - - <!-- Zip aligns the APK --> - <zipalign-helper in.package="${out.unaligned.file}" - out.package="${out.release.file}" /> - <echo>Release Package: ${out.release.file}</echo> - </target> - - <target name="install" depends="debug" - description="Installs/reinstalls the debug package onto a running - emulator or device. If the application was previously installed, - the signatures must match." > - <install-helper /> - </target> - - <target name="-uninstall-check"> - <condition property="uninstall.run"> - <isset property="manifest.package" /> - </condition> - </target> - - <target name="-uninstall-error" depends="-uninstall-check" unless="uninstall.run"> - <echo>Unable to run 'ant uninstall', manifest.package property is not defined. - </echo> - </target> - - <!-- Uninstalls the package from the default emulator/device --> - <target name="uninstall" depends="-uninstall-error" if="uninstall.run" - description="Uninstalls the application from a running emulator or device."> - <echo>Uninstalling ${manifest.package} from the default emulator or device...</echo> - <exec executable="${adb}" failonerror="true"> - <arg line="${adb.device.arg}" /> - <arg value="uninstall" /> - <arg value="${manifest.package}" /> + <exec executable="${aapt}" failonerror="true" > + <arg value="package" /> + <arg value="--version-code" /> + <arg value="${my.version.code}" /> + <arg value="--version-name" /> + <arg value="${my.version.name}" /> + <arg value="-f" /> + <arg value="-m" /> + <arg value="-M" /> + <arg value="AndroidManifest.xml" /> + <arg value="-I" /> + <arg value="${android.jar}" /> + <arg value="-S" /> + <arg value="${resource.absolute.dir}" /> + <arg value="-J" /> + <arg value="${gen.absolute.dir}" /> + <arg value="-F" /> + <arg value="${out.absolute.dir}/${resource.package.file.name}" /> </exec> </target> - <target name="clean" description="Removes output files created by other targets."> - <delete dir="${out.absolute.dir}" verbose="${verbose}" /> - <delete dir="${gen.absolute.dir}" verbose="${verbose}" /> - </target> - - <!-- Targets for code-coverage measurement purposes, invoked from external file --> - - <!-- Emma-instruments tested project classes (compiles the tested project if necessary) - and writes instrumented classes to ${instrumentation.absolute.dir}/classes --> - <target name="-emma-instrument" depends="compile"> - <echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo> - <!-- It only instruments class files, not any external libs --> - <emma enabled="true"> - <instr verbosity="${verbosity}" - mode="overwrite" - instrpath="${out.absolute.dir}/classes" - outdir="${out.absolute.dir}/classes"> - </instr> - <!-- TODO: exclusion filters on R*.class and allowing custom exclusion from - user defined file --> - </emma> - </target> - - <target name="-dex-instrumented" depends="-emma-instrument"> - <dex-helper> - <extra-parameters> - <arg value="--no-locals" /> - </extra-parameters> - <external-libs> - <fileset file="${emma.dir}/emma_device.jar" /> - </external-libs> - </dex-helper> - </target> - - <!-- Invoked from external files for code coverage purposes --> - <target name="-package-with-emma" depends="-dex-instrumented, -package-resources"> - <package-helper - output.filepath="${out.debug.unaligned.file}"> - <extra-jars> - <!-- Injected from external file --> - <jarfile path="${emma.dir}/emma_device.jar" /> - </extra-jars> - </package-helper> - </target> - - <target name="-debug-with-emma" depends="-set-debug-mode, -package-with-emma"> - <zipalign-helper in.package="${out.debug.unaligned.file}" - out.package="${out.debug.file}" /> - </target> - - <target name="-install-with-emma" depends="-debug-with-emma"> - <install-helper /> - </target> - - <!-- End of targets for code-coverage measurement purposes --> - - <target name="help"> - <!-- displays starts at col 13 - |13 80| --> - <echo>Android Ant Build. Available targets:</echo> - <echo> help: Displays this help.</echo> - <echo> clean: Removes output files created by other targets.</echo> - <echo> compile: Compiles project's .java files into .class files.</echo> - <echo> debug: Builds the application and signs 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/reinstalls the debug package onto a running</echo> - <echo> emulator or device.</echo> - <echo> If the application was previously installed, the</echo> - <echo> signatures must match.</echo> - <echo> uninstall: Uninstalls the application from a running emulator or</echo> - <echo> device.</echo> - </target> </project> diff --git a/android/default.properties b/android/default.properties index 4513a1e4f..0b9250e02 100644 --- a/android/default.properties +++ b/android/default.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-3 +target=android-8 diff --git a/android/scripts/setversion.sh b/android/scripts/setversion.sh index 4833d95ac..bf4e6b9d8 100755 --- a/android/scripts/setversion.sh +++ b/android/scripts/setversion.sh @@ -49,6 +49,8 @@ VERSIONINT=$(( \ )) echo "Android version: '$VERSIONSTRING' (${VERSIONINT})" +echo "my.version.name=${VERSIONSTRING}" > version.properties +echo "my.version.code=${VERSIONINT}" >> version.properties SUBST='s/android.versionCode="[0-9]"/android.versionCode="'${VERSIONINT}'"/' sed "$SUBST" < $MANIFEST > $TMP diff --git a/android/src/net/i2p/router/I2PAndroid.java b/android/src/net/i2p/router/I2PAndroid.java index 3c9c92bef..5210193a9 100644 --- a/android/src/net/i2p/router/I2PAndroid.java +++ b/android/src/net/i2p/router/I2PAndroid.java @@ -6,6 +6,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; +import android.os.Build; import android.os.Bundle; import java.io.File; @@ -19,11 +20,12 @@ import net.i2p.data.DataHelper; import net.i2p.router.Router; import net.i2p.router.RouterLaunch; import net.i2p.util.OrderedProperties; +import net.i2p.util.NativeBigInteger; public class I2PAndroid extends Activity { static Context _context; - private String DIR = "/data/data/net.i2p.router/files"; + private String _myDir; /** Called when the activity is first created. */ @Override @@ -33,12 +35,13 @@ public class I2PAndroid extends Activity setContentView(R.layout.main); _context = this; // Activity extends Context - DIR = getFilesDir().getAbsolutePath(); + _myDir = getFilesDir().getAbsolutePath(); debugStuff(); initialize(); - // 300ms per run + // 300ms per run on emulator on eeepc // 5x slower than java on my server and 50x slower than native on my server - // NativeBigInteger.main(null); + // 33 ms native 29 ms java moto droid 2.2.2 + NativeBigInteger.main(null); } public void onRestart() @@ -104,9 +107,13 @@ public class I2PAndroid extends Activity System.err.println("user.dir" + ": " + System.getProperty("user.dir")); System.err.println("user.home" + ": " + System.getProperty("user.home")); System.err.println("user.name" + ": " + System.getProperty("user.name")); - System.err.println("getFilesDir()" + ": " + DIR); + System.err.println("getFilesDir()" + ": " + _myDir); System.err.println("Package" + ": " + getPackageName()); System.err.println("Version" + ": " + getOurVersion()); + System.err.println("MODEL" + ": " + Build.MODEL); + System.err.println("DISPLAY" + ": " + Build.DISPLAY); + System.err.println("VERSION" + ": " + Build.VERSION.RELEASE); + System.err.println("SDK" + ": " + Build.VERSION.SDK); } private String getOurVersion() { @@ -127,9 +134,9 @@ public class I2PAndroid extends Activity copyResourceToFile(R.raw.blocklist_txt, "blocklist.txt"); // Set up the locations so Router and WorkingDir can find them - System.setProperty("i2p.dir.base", DIR); - System.setProperty("i2p.dir.config", DIR); - System.setProperty("wrapper.logfile", DIR + "/wrapper.log"); + System.setProperty("i2p.dir.base", _myDir); + System.setProperty("i2p.dir.config", _myDir); + System.setProperty("wrapper.logfile", _myDir + "/wrapper.log"); } private void copyResourceToFile(int resID, String f) { @@ -178,7 +185,7 @@ public class I2PAndroid extends Activity } catch (IOException ioe) { System.err.println("Creating file " + f + " from resource"); } finally { - try { fin.close(); } catch (IOException ioe) {} + if (fin != null) try { fin.close(); } catch (IOException ioe) {} } DataHelper.storeProps(props, getFileStreamPath(f)); diff --git a/core/java/src/net/i2p/util/NativeBigInteger.java b/core/java/src/net/i2p/util/NativeBigInteger.java index 730972bab..2859488c0 100644 --- a/core/java/src/net/i2p/util/NativeBigInteger.java +++ b/core/java/src/net/i2p/util/NativeBigInteger.java @@ -498,15 +498,10 @@ public class NativeBigInteger extends BigInteger { return true; } catch (UnsatisfiedLinkError ule) { if (_isAndroid) { - // temp debug + // Unfortunately, + // this is not interesting on Android, it says "file not found" + // on link errors too. warn("jbigi loadLibrary() fail", ule); - try { - System.load("/data/data/net.i2p.router/lib/libjbigi.so"); - return true; - } catch (Throwable t) { - warn("jbigi load() fail", t); - } - warn("Is the file there? " + (new File("/data/data/net.i2p.router/lib/libjbigi.so")).exists()); } return false; } -- GitLab