- More efficient build of i2p.jar and crypto.jar
  - More build fixes
  - Merge package configuration resource with configuration file on device if it exists
  - Add launcher icon, resized from installer/resources/eepsite.help/help/lib/itoopie.png
  - Start of a libjbigi build script
  - Increase min API to 3 so we can use JNI
This commit is contained in:
zzz
2011-06-04 00:29:02 +00:00
parent c3bcb8d020
commit 173343e049
8 changed files with 171 additions and 45 deletions

View File

@@ -5,10 +5,12 @@
android:versionName="1.0.0">
<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" />
<!-- 3 required for NDK -->
<uses-sdk android:minSdkVersion="3" />
<application android:label="@string/app_name">
<activity android:name="I2PAndroid"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher_itoopie"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@@ -28,16 +28,16 @@ SDK Platform-tools Version 5, June 2011.
# DO NOT create a new project or anything. It's all set up right here for you.
# Create the android 1.1 (API 2) virtual device
# Create the android 1.5 (API 3) virtual device
# (don't make a custom hardware profile)
# A AVD created with the 1.5 SDK will not work with the newer tools
../../android-sdk-linux_86/tools/android create avd --name i2p --target 2
../../android-sdk-linux_86/tools/android create avd --name i2p --target 3
#then run the emulator:
../../android-sdk-linux_86/tools/emulator -avd i2p &
#then wait a couple minutes until the emulator is up
#then install the I2P app (ONE TIME ONLY)
#then install the I2P app
ant install
#then run the debugger
@@ -47,3 +47,6 @@ ant install
ant reinstall
# Now click on the I2P icon on your phone!
#other helpful commands
../../android-sdk-linux_86/tools/adb shell

View File

@@ -83,42 +83,36 @@
<copy file="../build/router.jar" todir="${jar.libs.dir}" />
<!-- core -->
<mkdir dir="tmp" />
<unjar src="../build/i2p.jar" dest="tmp/" />
<delete file="tmp/net/i2p/util/LogWriter.class" />
<delete file="tmp/net/i2p/util/SecureDirectory.class" />
<delete file="tmp/net/i2p/util/SecureFile.class" />
<delete file="tmp/net/i2p/util/SecureFileOutputStream.class" />
<!-- org.bouncycastle.crypto already in android
but we need a little trickery because our HMac is incompatible...
and the libs aren't in the SDK to compile against??? -->
<jar destfile="${jar.libs.dir}/crypto.jar" >
<fileset dir="tmp/" >
<zipfileset src="../build/i2p.jar" >
<include name="org/bouncycastle/crypto/Digest.class" />
<include name="org/bouncycastle/crypto/Mac.class" />
<include name="org/bouncycastle/crypto/digests/GeneralDigest.class" />
<include name="org/bouncycastle/crypto/digests/MD5Digest.class" />
</fileset>
</zipfileset >
</jar>
<delete>
<fileset dir="tmp/" >
<include name="org/bouncycastle/crypto/Digest.class" />
<include name="org/bouncycastle/crypto/Mac.class" />
<include name="org/bouncycastle/crypto/digests/GeneralDigest.class" />
<include name="org/bouncycastle/crypto/digests/MD5Digest.class" />
</fileset>
</delete>
<!--
<delete dir="tmp/org/bouncycastle/" />
<delete file="tmp/net/i2p/crypto/HMACGenerator.class" />
-->
<delete file="tmp/org/bouncycastle/" />
<!-- lots of unneeded stuff could be deleted here -->
<jar destfile="${jar.libs.dir}/i2p.jar" basedir="tmp/" />
<delete dir="tmp/" />
<!-- some resources -->
<mkdir dir="res/drawable/" />
<!-- lots of unneeded stuff could be deleted here -->
<jar destfile="${jar.libs.dir}/i2p.jar" >
<zipfileset src="../build/i2p.jar" >
<exclude name="net/i2p/util/LogWriter.class" />
<exclude name="net/i2p/util/SecureDirectory.class" />
<exclude name="net/i2p/util/SecureFile.class" />
<exclude name="net/i2p/util/SecureFileOutputStream.class" />
<exclude name="org/bouncycastle/crypto/Digest.class" />
<exclude name="org/bouncycastle/crypto/Mac.class" />
<exclude name="org/bouncycastle/crypto/digests/GeneralDigest.class" />
<exclude name="org/bouncycastle/crypto/digests/MD5Digest.class" />
</zipfileset >
</jar>
</target>
<!-- some resources -->
<target name="copy-i2p-resources" depends="-dirs" >
<copy file="../installer/resources/themes/console/images/i2plogo.png" todir="res/drawable/" />
<copy file="../installer/resources/blocklist.txt" tofile="res/raw/blocklist_txt" />
</target>
@@ -127,14 +121,27 @@
<delete file="${jar.libs.dir}/crypto.jar" />
</target>
<target name="jbigi">
<exec executable="sh" osfamily="unix" failonerror="true">
<arg value="-c" />
<arg value="jni/build.sh" />
</exec>
<copy file="jni/libjbigi.so" todir="${native.libs.dir}/armeabi" />
<exec executable="chmod" osfamily="unix" failonerror="true">
<arg value="+x" />
<arg value="${native.libs.dir}/armeabi/libjbigi.so" />
</exec>
</target>
<!-- install now does both -->
<target name="reinstall" depends="install" />
<target name="distclean" depends="clean">
<delete dir="${jar.libs.dir}" verbose="${verbose}" />
<delete dir="tmp/" verbose="${verbose}" />
<delete file="res/drawable/i2plogo.png" verbose="${verbose}"/>
<delete file="res/raw/blocklist_txt" verbose="${verbose}" />
<delete dir="jni/build/" verbose="${verbose}" />
<delete file="jni/libjbigi.so" verbose="${verbose}" />
</target>
<!--
@@ -439,7 +446,8 @@
<!-- empty default pre-build target. Create a similar target in
your build.xml and it'll be called instead of this one. -->
<target name="-pre-build"/>
<!-- I2P add depends -->
<target name="-pre-build" depends="copy-i2p-resources" />
<!-- Generates the R.java file for this project's resources. -->
<target name="-resource-src" depends="-dirs">
@@ -522,6 +530,7 @@
<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}"
@@ -544,7 +553,7 @@
<!-- 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" />
<target name="-post-compile" depends="hackcleanup, jbigi" />
<!-- Obfuscate target
This is only active in release builds when proguard.config is defined

View File

@@ -8,4 +8,4 @@
# project structure.
# Project target.
target=android-2
target=android-3

76
android/jni/build.sh Executable file
View File

@@ -0,0 +1,76 @@
#
# build GMP and libjbigi.so using the Android tools directly
#
THISDIR=$(realpath $(dirname $(which $0)))
cd $THISDIR
export NDK=$(realpath ../../../android-ndk-r5b/)
LEVEL=3
ARCH=arm
export SYSROOT=$NDK/platforms/android-$LEVEL/arch-$ARCH/
export AABI=arm-linux-androideabi-4.4.3
export SYSTEM=linux-x86
export BINPREFIX=arm-linux-androideabi-
export CC="$NDK/toolchains/$AABI/prebuilt/$SYSTEM/bin/${BINPREFIX}gcc --sysroot=$SYSROOT"
#echo "CC is $CC"
JBIGI=$(realpath ../../core/c/jbigi)
GMPVER=5.0.2
GMP=$JBIGI/gmp-$GMPVER
if [ ! -d $GMP ]
then
echo "Source dir for GMP version $GMPVER not found in $GMP"
echo "Install it there or change GMPVER and/or GMP in this script"
exit 1
fi
LIBFILE=$PWD/libjbigi.so
if [ -f $LIBFILE ]
then
echo "$LIBFILE exists, nothing to do here"
echo "If you wish to force a recompile, delete it"
exit 0
fi
mkdir -p build
cd build
# we must set both build and host, so that the configure
# script will set cross_compile=yes, so that it
# won't attempt to run the a.out files
if [ ! -f config.status ]
then
echo "Configuring GMP..."
$GMP/configure --with-pic --build=arm --host=x86 || exit 1
fi
echo "Building GMP..."
make || exit 1
export JAVA_HOME=$(dirname $(dirname $(realpath $(which javac))))
if [ ! -f "$JAVA_HOME/include/jni.h" ]; then
echo "Cannot find jni.h! Looked in '$JAVA_HOME/include/jni.h'"
echo "Please set JAVA_HOME to a java home that has the JNI"
exit 1
fi
COMPILEFLAGS="-fPIC -Wall"
INCLUDES="-I. -I$JBIGI/jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
LINKFLAGS="-shared -Wl,-soname,libjbigi.so,--fix-cortex-a8"
echo "Building jbigi lib that is statically linked to GMP"
STATICLIBS=".libs/libgmp.a"
echo "Compiling C code..."
rm -f jbigi.o $LIBFILE
echo "$CC -c $COMPILEFLAGS $INCLUDES $JBIGI/jbigi/src/jbigi.c"
$CC -c $COMPILEFLAGS $INCLUDES $JBIGI/jbigi/src/jbigi.c || exit 1
echo "$CC $LINKFLAGS $INCLUDES $INCLUDELIBS -o $LIBFILE jbigi.o $STATICLIBS"
$CC $LINKFLAGS $INCLUDES $INCLUDELIBS -o $LIBFILE jbigi.o $STATICLIBS || exit 1
ls -l $LIBFILE || exit 1
echo 'Built successfully'

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@@ -1,6 +1,8 @@
logger.defaultLevel=INFO
logger.record.net.i2p.util.LogWriter=WARN
logger.record.net.i2p.router.peerManager.ProfileOrganizer=WARN
logger.record.net.i2p.router.transport=WARN
logger.record.net.i2p.router.transport.FIFOBandwidthRefiller=ERROR
logger.record.net.i2p.stat.Rate=ERROR
logger.record.net.i2p.util.LogManager=WARN
logger.record.net.i2p.util.LogWriter=WARN
logger.record.net.i2p.util.NativeBigInteger=DEBUG

View File

@@ -11,15 +11,17 @@ import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import net.i2p.data.DataHelper;
import net.i2p.router.Router;
import net.i2p.router.RouterLaunch;
// import net.i2p.util.NativeBigInteger;
import net.i2p.util.OrderedProperties;
public class I2PAndroid extends Activity
{
static Context _context;
private static final String DIR = "/data/data/net.i2p.router/files";
private String DIR = "/data/data/net.i2p.router/files";
/** Called when the activity is first created. */
@Override
@@ -29,6 +31,7 @@ public class I2PAndroid extends Activity
setContentView(R.layout.main);
_context = this; // Activity extends Context
DIR = getFilesDir().getAbsolutePath();
debugStuff();
initialize();
// 300ms per run
@@ -99,17 +102,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);
}
private void initialize() {
// Until we can edit the router.config on the device,
// copy it from the resource every time.
// File f = new I2PFile("router.config");
// if (!f.exists()) {
copyResourceToFile(R.raw.router_config, "router.config");
copyResourceToFile(R.raw.logger_config, "logger.config");
copyResourceToFile(R.raw.blocklist_txt, "blocklist.txt");
// }
mergeResourceToFile(R.raw.router_config, "router.config");
mergeResourceToFile(R.raw.logger_config, "logger.config");
copyResourceToFile(R.raw.blocklist_txt, "blocklist.txt");
// Set up the locations so Router and WorkingDir can find them
System.setProperty("i2p.dir.base", DIR);
@@ -140,4 +139,39 @@ public class I2PAndroid extends Activity
}
}
/**
* Load defaults from resource,
* then add props from file,
* and write back
*/
private void mergeResourceToFile(int resID, String f) {
InputStream in = null;
InputStream fin = null;
byte buf[] = new byte[4096];
try {
Properties props = new OrderedProperties();
// Context methods
in = getResources().openRawResource(resID);
DataHelper.loadProps(props, in);
try {
fin = openFileInput(f);
DataHelper.loadProps(props, fin);
System.err.println("Merging resource into file " + f);
} catch (IOException ioe) {
System.err.println("Creating file " + f + " from resource");
} finally {
try { fin.close(); } catch (IOException ioe) {}
}
DataHelper.storeProps(props, getFileStreamPath(f));
} catch (IOException ioe) {
} catch (Resources.NotFoundException nfe) {
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
if (fin != null) try { fin.close(); } catch (IOException ioe) {}
}
}
}