mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 01:53:00 +08:00
CB-3358: Change Commons-codec:base64 to Android:Base64
This commit is contained in:
parent
8077091b34
commit
78efe2a960
@ -14,7 +14,6 @@ Requires
|
|||||||
- Java JDK 1.5 or greater
|
- Java JDK 1.5 or greater
|
||||||
- Apache ANT 1.8.0 or greater
|
- Apache ANT 1.8.0 or greater
|
||||||
- Android SDK [http://developer.android.com](http://developer.android.com)
|
- Android SDK [http://developer.android.com](http://developer.android.com)
|
||||||
- Apache Commons Codec [http://commons.apache.org/codec/](http://commons.apache.org/codec/)
|
|
||||||
|
|
||||||
|
|
||||||
Cordova Android Developer Tools
|
Cordova Android Developer Tools
|
||||||
@ -83,11 +82,7 @@ Note: The Developer Tools handle this. This is only to be done if the tooling f
|
|||||||
you are developing directly against the framework.
|
you are developing directly against the framework.
|
||||||
|
|
||||||
|
|
||||||
To create your `cordova.jar` file, copy the commons codec:
|
To create your `cordova.jar` file, run in the framework directory:
|
||||||
|
|
||||||
mv commons-codec-1.7.jar framework/libs
|
|
||||||
|
|
||||||
then run in the framework directory:
|
|
||||||
|
|
||||||
android update project -p . -t android-17
|
android update project -p . -t android-17
|
||||||
ant jar
|
ant jar
|
||||||
|
10
bin/create
10
bin/create
@ -99,16 +99,6 @@ then
|
|||||||
# update the cordova-android framework for the desired target
|
# update the cordova-android framework for the desired target
|
||||||
"$ANDROID_BIN" update project --target $TARGET --path "$BUILD_PATH"/framework &> /dev/null
|
"$ANDROID_BIN" update project --target $TARGET --path "$BUILD_PATH"/framework &> /dev/null
|
||||||
|
|
||||||
if [ ! -e "$BUILD_PATH"/framework/libs/commons-codec-1.7.jar ]; then
|
|
||||||
# Use curl to get the jar (TODO: Support Apache Mirrors)
|
|
||||||
curl -OL http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip &> /dev/null
|
|
||||||
unzip commons-codec-1.7-bin.zip &> /dev/null
|
|
||||||
mkdir -p "$BUILD_PATH"/framework/libs
|
|
||||||
cp commons-codec-1.7/commons-codec-1.7.jar "$BUILD_PATH"/framework/libs
|
|
||||||
# cleanup yo
|
|
||||||
rm commons-codec-1.7-bin.zip && rm -rf commons-codec-1.7
|
|
||||||
fi
|
|
||||||
|
|
||||||
# compile cordova.js and cordova.jar
|
# compile cordova.js and cordova.jar
|
||||||
pushd "$BUILD_PATH"/framework > /dev/null
|
pushd "$BUILD_PATH"/framework > /dev/null
|
||||||
ant jar > /dev/null
|
ant jar > /dev/null
|
||||||
|
@ -120,46 +120,6 @@ function cleanup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadCommonsCodec() {
|
|
||||||
if (!fso.FileExists(ROOT + '\\framework\\libs\\commons-codec-1.7.jar')) {
|
|
||||||
// We need the .jar
|
|
||||||
var url = 'http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip';
|
|
||||||
var libsPath = ROOT + '\\framework\\libs';
|
|
||||||
var savePath = libsPath + '\\commons-codec-1.7-bin.zip';
|
|
||||||
if (!fso.FileExists(savePath)) {
|
|
||||||
if(!fso.FolderExists(ROOT + '\\framework\\libs')) {
|
|
||||||
fso.CreateFolder(libsPath);
|
|
||||||
}
|
|
||||||
// We need the zip to get the jar
|
|
||||||
var xhr = WScript.CreateObject('MSXML2.XMLHTTP');
|
|
||||||
xhr.open('GET', url, false);
|
|
||||||
xhr.send();
|
|
||||||
if (xhr.status == 200) {
|
|
||||||
var stream = WScript.CreateObject('ADODB.Stream');
|
|
||||||
stream.Open();
|
|
||||||
stream.Type = 1;
|
|
||||||
stream.Write(xhr.ResponseBody);
|
|
||||||
stream.Position = 0;
|
|
||||||
stream.SaveToFile(savePath);
|
|
||||||
stream.Close();
|
|
||||||
} else {
|
|
||||||
Log('Could not retrieve the commons-codec. Please download it yourself and put into the framework/libs directory. This process may fail now. Sorry.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var app = WScript.CreateObject('Shell.Application');
|
|
||||||
var source = app.NameSpace(savePath).Items();
|
|
||||||
var target = app.NameSpace(ROOT + '\\framework\\libs');
|
|
||||||
target.CopyHere(source, 256);
|
|
||||||
|
|
||||||
// Move the jar into libs
|
|
||||||
fso.MoveFile(ROOT + '\\framework\\libs\\commons-codec-1.7\\commons-codec-1.7.jar', ROOT + '\\framework\\libs\\commons-codec-1.7.jar');
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
fso.DeleteFile(ROOT + '\\framework\\libs\\commons-codec-1.7-bin.zip');
|
|
||||||
fso.DeleteFolder(ROOT + '\\framework\\libs\\commons-codec-1.7', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// working dir
|
// working dir
|
||||||
var ROOT = WScript.ScriptFullName.split('\\bin\\create.js').join('');
|
var ROOT = WScript.ScriptFullName.split('\\bin\\create.js').join('');
|
||||||
if (args.Count() > 0) {
|
if (args.Count() > 0) {
|
||||||
@ -206,8 +166,6 @@ if (!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.jar') &&
|
|||||||
Log("Building jar and js files...");
|
Log("Building jar and js files...");
|
||||||
// update the cordova framework project to a target that exists on this machine
|
// update the cordova framework project to a target that exists on this machine
|
||||||
exec('android.bat update project --target "'+TARGET+'" --path "'+ROOT+'\\framework"');
|
exec('android.bat update project --target "'+TARGET+'" --path "'+ROOT+'\\framework"');
|
||||||
// pull down commons codec if necessary
|
|
||||||
downloadCommonsCodec();
|
|
||||||
exec('ant.bat -f "'+ ROOT +'\\framework\\build.xml" jar');
|
exec('ant.bat -f "'+ ROOT +'\\framework\\build.xml" jar');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
bin/update
10
bin/update
@ -105,16 +105,6 @@ then
|
|||||||
# update the cordova-android framework for the desired target
|
# update the cordova-android framework for the desired target
|
||||||
"$ANDROID_BIN" update project --target $TARGET --path "$BUILD_PATH"/framework &> /dev/null
|
"$ANDROID_BIN" update project --target $TARGET --path "$BUILD_PATH"/framework &> /dev/null
|
||||||
|
|
||||||
if [ ! -e "$BUILD_PATH"/framework/libs/commons-codec-1.7.jar ]; then
|
|
||||||
# Use curl to get the jar (TODO: Support Apache Mirrors)
|
|
||||||
curl -OL http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip &> /dev/null
|
|
||||||
unzip commons-codec-1.7-bin.zip &> /dev/null
|
|
||||||
mkdir -p "$BUILD_PATH"/framework/libs
|
|
||||||
cp commons-codec-1.7/commons-codec-1.7.jar "$BUILD_PATH"/framework/libs
|
|
||||||
# cleanup yo
|
|
||||||
rm commons-codec-1.7-bin.zip && rm -rf commons-codec-1.7
|
|
||||||
fi
|
|
||||||
|
|
||||||
# compile cordova.js and cordova.jar
|
# compile cordova.js and cordova.jar
|
||||||
(cd "$BUILD_PATH"/framework && ant jar &> /dev/null )
|
(cd "$BUILD_PATH"/framework && ant jar &> /dev/null )
|
||||||
fi
|
fi
|
||||||
|
@ -96,46 +96,6 @@ function cleanup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadCommonsCodec() {
|
|
||||||
if (!fso.FileExists(ROOT + '\\framework\\libs\\commons-codec-1.7.jar')) {
|
|
||||||
// We need the .jar
|
|
||||||
var url = 'http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip';
|
|
||||||
var libsPath = ROOT + '\\framework\\libs';
|
|
||||||
var savePath = libsPath + '\\commons-codec-1.7-bin.zip';
|
|
||||||
if (!fso.FileExists(savePath)) {
|
|
||||||
if(!fso.FolderExists(ROOT + '\\framework\\libs')) {
|
|
||||||
fso.CreateFolder(libsPath);
|
|
||||||
}
|
|
||||||
// We need the zip to get the jar
|
|
||||||
var xhr = WScript.CreateObject('MSXML2.XMLHTTP');
|
|
||||||
xhr.open('GET', url, false);
|
|
||||||
xhr.send();
|
|
||||||
if (xhr.status == 200) {
|
|
||||||
var stream = WScript.CreateObject('ADODB.Stream');
|
|
||||||
stream.Open();
|
|
||||||
stream.Type = 1;
|
|
||||||
stream.Write(xhr.ResponseBody);
|
|
||||||
stream.Position = 0;
|
|
||||||
stream.SaveToFile(savePath);
|
|
||||||
stream.Close();
|
|
||||||
} else {
|
|
||||||
WScript.Echo('Could not retrieve the commons-codec. Please download it yourself and put into the framework/libs directory. This process may fail now. Sorry.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var app = WScript.CreateObject('Shell.Application');
|
|
||||||
var source = app.NameSpace(savePath).Items();
|
|
||||||
var target = app.NameSpace(ROOT + '\\framework\\libs');
|
|
||||||
target.CopyHere(source, 256);
|
|
||||||
|
|
||||||
// Move the jar into libs
|
|
||||||
fso.MoveFile(ROOT + '\\framework\\libs\\commons-codec-1.7\\commons-codec-1.7.jar', ROOT + '\\framework\\libs\\commons-codec-1.7.jar');
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
fso.DeleteFile(ROOT + '\\framework\\libs\\commons-codec-1.7-bin.zip');
|
|
||||||
fso.DeleteFolder(ROOT + '\\framework\\libs\\commons-codec-1.7', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var args = WScript.Arguments, PROJECT_PATH="example",
|
var args = WScript.Arguments, PROJECT_PATH="example",
|
||||||
shell=WScript.CreateObject("WScript.Shell");
|
shell=WScript.CreateObject("WScript.Shell");
|
||||||
|
|
||||||
@ -161,8 +121,6 @@ if (!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.jar') &&
|
|||||||
WScript.Echo("Building jar and js files...");
|
WScript.Echo("Building jar and js files...");
|
||||||
// update the cordova framework project to a target that exists on this machine
|
// update the cordova framework project to a target that exists on this machine
|
||||||
exec('android.bat update project --target '+TARGET+' --path '+ROOT+'\\framework');
|
exec('android.bat update project --target '+TARGET+' --path '+ROOT+'\\framework');
|
||||||
// pull down commons codec if necessary
|
|
||||||
downloadCommonsCodec();
|
|
||||||
exec('ant.bat -f \"'+ ROOT +'\\framework\\build.xml\" jar');
|
exec('ant.bat -f \"'+ ROOT +'\\framework\\build.xml\" jar');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,22 +31,6 @@
|
|||||||
<fail message="The required minimum version of ant is 1.8.0, you have ${ant.version}"
|
<fail message="The required minimum version of ant is 1.8.0, you have ${ant.version}"
|
||||||
unless="thisantversion" />
|
unless="thisantversion" />
|
||||||
|
|
||||||
<!-- check that commons codec is available. You should copy the codec jar to
|
|
||||||
framework/libs, as it is not included in the Cordova distribution.
|
|
||||||
The name of the jar file in framework/libs does not matter. -->
|
|
||||||
<available classname="org.apache.commons.codec.binary.Base64"
|
|
||||||
property="exists.base64"
|
|
||||||
ignoresystemclasses="true">
|
|
||||||
<classpath>
|
|
||||||
<pathelement path="${classpath}" />
|
|
||||||
<fileset dir="libs">
|
|
||||||
<include name="*.jar" />
|
|
||||||
</fileset>
|
|
||||||
</classpath>
|
|
||||||
</available>
|
|
||||||
<fail message="You need to put a copy of Apache Commons Codec jar in the framework/libs directory"
|
|
||||||
unless="exists.base64" />
|
|
||||||
|
|
||||||
<!-- The local.properties file is created and updated by the 'android'
|
<!-- The local.properties file is created and updated by the 'android'
|
||||||
tool. (For example "sdkdir/tools/android update project -p ." inside
|
tool. (For example "sdkdir/tools/android update project -p ." inside
|
||||||
of this directory where the AndroidManifest.xml file exists. This
|
of this directory where the AndroidManifest.xml file exists. This
|
||||||
|
@ -26,7 +26,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.apache.cordova.api.CallbackContext;
|
import org.apache.cordova.api.CallbackContext;
|
||||||
import org.apache.cordova.api.CordovaPlugin;
|
import org.apache.cordova.api.CordovaPlugin;
|
||||||
import org.apache.cordova.api.DataResource;
|
import org.apache.cordova.api.DataResource;
|
||||||
@ -48,6 +47,7 @@ import android.media.MediaScannerConnection.MediaScannerConnectionClient;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -778,7 +778,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
try {
|
try {
|
||||||
if (bitmap.compress(CompressFormat.JPEG, mQuality, jpeg_data)) {
|
if (bitmap.compress(CompressFormat.JPEG, mQuality, jpeg_data)) {
|
||||||
byte[] code = jpeg_data.toByteArray();
|
byte[] code = jpeg_data.toByteArray();
|
||||||
byte[] output = Base64.encodeBase64(code);
|
byte[] output = Base64.encode(code, Base64.DEFAULT);
|
||||||
String js_out = new String(output);
|
String js_out = new String(output);
|
||||||
this.callbackContext.success(js_out);
|
this.callbackContext.success(js_out);
|
||||||
js_out = null;
|
js_out = null;
|
||||||
|
@ -20,9 +20,9 @@ package org.apache.cordova;
|
|||||||
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.apache.cordova.api.CallbackContext;
|
import org.apache.cordova.api.CallbackContext;
|
||||||
import org.apache.cordova.api.CordovaPlugin;
|
import org.apache.cordova.api.CordovaPlugin;
|
||||||
import org.apache.cordova.api.DataResource;
|
import org.apache.cordova.api.DataResource;
|
||||||
@ -912,7 +912,7 @@ public class FileUtils extends CordovaPlugin {
|
|||||||
break;
|
break;
|
||||||
default: // Base64.
|
default: // Base64.
|
||||||
String contentType = dataResource.getMimeType();
|
String contentType = dataResource.getMimeType();
|
||||||
byte[] base64 = Base64.encodeBase64(bytes);
|
byte[] base64 = Base64.encode(bytes, Base64.DEFAULT);
|
||||||
String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII");
|
String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII");
|
||||||
result = new PluginResult(PluginResult.Status.OK, s);
|
result = new PluginResult(PluginResult.Status.OK, s);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user