1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-08 12:15:49 +00:00

Android: Implement Gradle build for easy debugging

Adds a CoreSideLoadingActivity to sideload cores for debugging purposes.
Adds instructions on how to debug both the RetroArch frontend and cores from within Android Studio

Co-authored-by: natinusala <natinusala@gmail.com>
This commit is contained in:
langerhans 2018-12-22 00:23:54 +01:00
parent 0d7cb7edc2
commit 3c5a391c9e
14 changed files with 802 additions and 0 deletions

135
pkg/android/phoenix-gradle/.gitignore vendored Normal file
View File

@ -0,0 +1,135 @@
# Created by https://www.gitignore.io/api/androidstudio
# Edit at https://www.gitignore.io/?templates=androidstudio
### AndroidStudio ###
# Covers files to be ignored for android development using Android Studio.
# Built application files
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle
.gradle/
build/
# Signing files
.signing/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio
/*/build/
/*/local.properties
/*/out
/*/*/build
/*/*/production
captures/
.navigation/
*.ipr
*~
*.swp
# Android Patch
gen-external-apklibs
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
# NDK
obj/
# IntelliJ IDEA
*.iml
*.iws
/out/
# User-specific configurations
.idea/caches/
.idea/libraries/
.idea/shelf/
.idea/workspace.xml
.idea/tasks.xml
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/encodings.xml
.idea/misc.xml
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
.idea/datasources.xml
.idea/dataSources.ids
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
.idea/assetWizardSettings.xml
# OS-specific files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Legacy Eclipse project files
.classpath
.project
.cproject
.settings/
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.war
*.ear
# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
hs_err_pid*
## Plugin-specific files:
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Mongo Explorer plugin
.idea/mongoSettings.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### AndroidStudio Patch ###
!/gradle/wrapper/gradle-wrapper.jar
# End of https://www.gitignore.io/api/androidstudio

View File

@ -0,0 +1,83 @@
Phoenix Gradle Build
====================
Implements a Gradle build based on the existing phoenix sources.
It is currently only useful for running and debugging the RetroArch frontend in Android Studio.
This is caused by the fact that this build can't support the same older API level that the old Ant
based build does. The minimum supported API level for this build is 16. Also this will not build the
mips variant cause support for this architecture has long been removed from the Android NDK.
The only file that had to be duplicated is the AndroidManifest.xml because the modern Android build
won't allow SDK versions defined in this file anymore. It's also easier to change the app name this way.
To get this running follow these steps:
* Install the Android SDK Platform 28
* Install the latest Android NDK
* Import the project into Android Studio
* Make sure to select the appropriate build variant for your device (32 or 64 bit)
Sideloading a core
------------------
The `CoreSideloadActivity` activity allows you to sideload and run a core (with content) from your computer through ADB.
**Keep in mind that forcefully stopping the process will not save any configuration you did in RetroArch. If you want your config to be saved, use "Quit RetroArch" in the main menu.**
Usage :
```
adb shell am force-stop <package>
adb push <core> /data/local/tmp
adb shell am start -n <package>/com.retroarch.browser.debug.CoreSideloadActivity --es "LIBRETRO" "/data/local/tmp/<core>" --es "ROM" "<content>"
```
Where `<package>` is the target RetroArch app package name :
- `com.retroarch` (RetroArch)
- `com.retroarch.aarch64` (RetroArch64)
`<content>` is the path to the content to load (on your device) (optional)
and `<core>` is the path to the core to sideload (on your computer).
Alternatively you can set up Android Studio so that it prompts you for a core file to sideload on launching the app.
In the Run/Debug configuration dialog add another run configuration as outlined in the following screenshot
![Sideload run configuration](sideload_core_android_studio.png)
Specifically take note of the Launch Options section and make sure to add a new step to the "Before launch" section that prompts for the
core file to load. The tool configuration is shown on the right. If yu run this configuration a file chooser dialog will show
where you can select the core to load. Keep in mind the filename is hardcoded so every time you load a different core it will be
overwritten. You can create multiple configurations like this to work around this limitation.
Debugging a core
----------------
This has so far only been tested with a limited number of cores that use ndk-build. In theory this also works with CMake, but that's currently untested.
Following is an example of what it takes to debug the dosbox-svn core in Android Studio. It is based on the sideload technique outlined above.
**Note**: Make sure the filename of the core does not get changed. Set up your Run/Debug configuration accordingly (Launch flags and ADB arguments)! Otherwise debugging will not work.
* Clone dosbox-svn next to your RetroArch repo
* Run `ndk-build NDK_DEBUG=1` in dosbox-svn/libretro/jni
* In Android Studio create a new Gradle module of type Android Library. You can delete everything but AndroidManifest.xml and build.gradle from the new directory.
* In the newly created build.gradle file add the following in the `defaultConfig {}` block:
```
ndk {
moduleName "dosbox-svn"
}
```
Also add the following in the `android {}` block:
```
externalNativeBuild {
ndkBuild {
path file('../../../../../dosbox-svn/libretro/jni/Android.mk')
}
}
```
* Let the offered Gradle Sync run. You should see the core sources pop up in Android Studio.
* Set a breakpoint in the core code.
* A good example to check if the setup is working is `retro_get_system_info` which is called on core load
* In the Run/Debug Configurations dialog in Android Studio under Debugger -> Symbol Directories make sure to have your core symbols loaded. You should have two directories there (as per your architecture and core):
* /path/to/phoenix-gradle/app/build/intermediates/ndkBuild/ra<32 or 64>/debug/obj/local/<your_arch>
* /path/to/dosbox-svn/libretro/obj/local/<your_arch>
* Start the app with the sideload debug config from Android Studio
* The breakpoint should trigger once the core gets loaded

View File

@ -0,0 +1,68 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.retroarch"
minSdkVersion 16
targetSdkVersion 28
ndk {
moduleName "retroarch-activity"
}
externalNativeBuild {
ndkBuild {
arguments "-j${Runtime.runtime.availableProcessors()}"
}
}
}
flavorDimensions "abi"
productFlavors {
ra32 {
dimension "abi"
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
resValue "string", "app_name", "RetroArch"
}
ra64 {
dimension "abi"
ndk {
abiFilters 'arm64-v8a', 'x86_64'
}
applicationIdSuffix '.aarch64'
resValue "string", "app_name", "RetroArch (AArch64)"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
externalNativeBuild {
ndkBuild {
path file('../../phoenix/jni/Android.mk')
}
}
sourceSets {
ra32 {
java.srcDirs = ['../../phoenix/src']
res.srcDirs = ['../../phoenix/res', '../../phoenix/libs/googleplay/res']
}
ra64 {
java.srcDirs = ['../../phoenix/src']
res.srcDirs = ['../../phoenix64/res', '../../phoenix64/libs/googleplay/res']
}
}
}
dependencies {
implementation files('../../phoenix/libs/googleplay/libs/google-play-services.jar')
}

View File

@ -0,0 +1,43 @@
<!-- <!DOCTYPE manifest [ <!ENTITY % versionDTD SYSTEM "../../../version.dtd"> %versionDTD; ]> !-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.retroarch"
android:versionCode="74"
android:versionName="1.7.5"
android:installLocation="internalOnly">
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
<uses-feature android:name="android.software.leanback" android:required="false" />
<uses-feature android:name="android.hardware.gamepad" android:required="false"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:hasCode="true"
android:isGame="true"
android:banner="@drawable/banner"
tools:ignore="GoogleAppIndexingWarning">
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<activity android:name="com.retroarch.browser.mainmenu.MainMenuActivity" android:exported="true" android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="tv.ouya.intent.category.GAME" />
</intent-filter>
</activity>
<activity android:name="com.retroarch.browser.retroactivity.RetroActivityFuture" android:exported="true" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleInstance">
<meta-data android:name="android.app.lib_name" android:value="retroarch-activity" />
<meta-data android:name="android.app.func_name" android:value="ANativeActivity_onCreate" />
</activity>
<activity android:name="com.retroarch.browser.retroactivity.RetroActivityPast" android:exported="true" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleInstance">
<meta-data android:name="android.app.lib_name" android:value="retroarch-activity" />
<meta-data android:name="android.app.func_name" android:value="ANativeActivity_onCreate" />
</activity>
<activity android:name="com.retroarch.browser.debug.CoreSideloadActivity" android:exported="true"/>
</application>
</manifest>

View File

@ -0,0 +1,17 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

172
pkg/android/phoenix-gradle/gradlew vendored Normal file
View File

@ -0,0 +1,172 @@
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

84
pkg/android/phoenix-gradle/gradlew.bat vendored Normal file
View File

@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -0,0 +1 @@
include ':app'

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

View File

@ -39,5 +39,6 @@
<meta-data android:name="android.app.lib_name" android:value="retroarch-activity" />
<meta-data android:name="android.app.func_name" android:value="ANativeActivity_onCreate" />
</activity>
<activity android:name="com.retroarch.browser.debug.CoreSideloadActivity" android:exported="true"/>
</application>
</manifest>

View File

@ -0,0 +1,192 @@
package com.retroarch.browser.debug;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
import android.widget.TextView;
import com.retroarch.browser.mainmenu.MainMenuActivity;
import com.retroarch.browser.preferences.util.UserPreferences;
import com.retroarch.browser.retroactivity.RetroActivityFuture;
import com.retroarch.browser.retroactivity.RetroActivityPast;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* This activity allows developers to sideload and run a core
* from their PC through adb
*
* Usage : see Phoenix Gradle Build README.md
*/
public class CoreSideloadActivity extends Activity
{
private static final String EXTRA_CORE = "LIBRETRO";
private static final String EXTRA_CONTENT = "ROM";
private TextView textView;
private CoreSideloadWorkerTask workerThread;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// The most simple layout is no layout at all
textView = new TextView(this);
setContentView(textView);
// Check that we have at least the core extra
if (!getIntent().hasExtra(EXTRA_CORE))
{
textView.setText("Missing extra \"LIBRETRO\"");
return;
}
// Start our worker thread
workerThread = new CoreSideloadWorkerTask(this, textView, getIntent().getStringExtra(EXTRA_CORE), getIntent().getStringExtra(EXTRA_CONTENT));
workerThread.execute();
}
@Override
protected void onDestroy() {
if (workerThread != null)
{
workerThread.cancel(true);
workerThread = null;
}
super.onDestroy();
}
private static class CoreSideloadWorkerTask extends AsyncTask<Void, Integer, String>
{
private TextView progressTextView;
private String core;
private String content;
private Activity ctx;
private File destination;
public CoreSideloadWorkerTask(Activity ctx, TextView progressTextView, String corePath, String contentPath)
{
this.progressTextView = progressTextView;
this.core = corePath;
this.ctx = ctx;
this.content = contentPath;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressTextView.setText("Sideloading...");
}
@Override
protected String doInBackground(Void... voids) {
File coreFile = new File(core);
File corePath = new File(UserPreferences.getPreferences(ctx).getString("libretro_path", ctx.getApplicationInfo().dataDir + "/cores/"));
// Check that both files exist
if (!coreFile.exists())
return "Input file doesn't exist (" + core + ")";
if (!corePath.exists())
return "Destination directory doesn't exist (" + corePath.getAbsolutePath() + ")";
destination = new File(corePath, coreFile.getName());
// Copy it
Log.d("sideload", "Copying " + coreFile.getAbsolutePath() + " to " + destination.getAbsolutePath());
long copied = 0;
long max = coreFile.length();
try
{
InputStream is = new FileInputStream(coreFile);
OutputStream os = new FileOutputStream(destination);
byte[] buf = new byte[1024];
int length;
while ((length = is.read(buf)) > 0)
{
os.write(buf, 0, length);
copied += length;
publishProgress((int)(copied / max * 100));
}
is.close();
os.close();
}
catch (IOException ex)
{
ex.printStackTrace();
return ex.getMessage();
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
if (values.length > 0)
progressTextView.setText("Sideloading: " + values[0] + "%");
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
// Everything went as expected
if (s == null)
{
progressTextView.setText("Done!");
// Run RA with our newly sideloaded core (and content)
Intent retro;
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB))
{
retro = new Intent(ctx, RetroActivityFuture.class);
}
else
{
retro = new Intent(ctx, RetroActivityPast.class);
}
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
retro.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Log.d("sideload", "Running RetroArch with core " + destination.getAbsolutePath());
MainMenuActivity.startRetroActivity(
retro,
content,
destination.getAbsolutePath(),
UserPreferences.getDefaultConfigPath(ctx),
Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD),
ctx.getApplicationInfo().dataDir,
ctx.getApplicationInfo().sourceDir);
ctx.startActivity(retro);
ctx.finish();
}
// An error occured
else
{
progressTextView.setText("Error: " + s);
}
}
}
}

View File

@ -39,5 +39,6 @@
<meta-data android:name="android.app.lib_name" android:value="retroarch-activity" />
<meta-data android:name="android.app.func_name" android:value="ANativeActivity_onCreate" />
</activity>
<activity android:name="com.retroarch.browser.debug.CoreSideloadActivity" android:exported="true"/>
</application>
</manifest>