retroshare-service now build and runs fine on android (even older ones)

This commit is contained in:
Gioacchino Mazzurco 2018-10-05 22:29:49 +02:00
parent 1d8bb44811
commit b28512b889
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
18 changed files with 296 additions and 46 deletions

View File

@ -252,3 +252,4 @@ your work-station running
- link:https://source.android.com/devices/tech/debug/gdb[]
- link:https://fw4spl-org.github.io/fw4spl-blog/2015/07/27/Native-debugging-on-Android-with-QtCreator.html[]
- link:https://fragglet.livejournal.com/19646.html[]
- link:https://github.com/android-ndk/ndk/issues/773[How to build without using standalone toolchain?]

View File

@ -14,7 +14,7 @@ function define_default_value()
## You are supposed to provide the following variables according to your system setup
define_default_value ANDROID_NDK_PATH "/opt/android-ndk/"
define_default_value ANDROID_NDK_ARCH "arm"
define_default_value ANDROID_PLATFORM_VER "21"
define_default_value ANDROID_PLATFORM_VER "16"
define_default_value NATIVE_LIBS_TOOLCHAIN_PATH "${HOME}/Builds/android-toolchains/retroshare-android-${ANDROID_PLATFORM_VER}-${ANDROID_NDK_ARCH}/"
define_default_value HOST_NUM_CPU $(nproc)
@ -35,7 +35,7 @@ define_default_value LIBUPNP_SOURCE_VERSION "1.6.25"
define_default_value LIBUPNP_SOURCE_SHA256 c5a300b86775435c076d58a79cc0d5a977d76027d2a7d721590729b7f369fa43
define_default_value INSTALL_QT_ANDROID "false"
define_default_value QT_VERSION "5.9.6"
define_default_value QT_VERSION "5.12.0"
define_default_value QT_ANDROID_INSTALLER_SHA256 a214084e2295c9a9f8727e8a0131c37255bf724bfc69e80f7012ba3abeb1f763
define_default_value RESTBED_SOURCE_VERSION "4.6"
@ -95,6 +95,15 @@ build_toolchain()
${ANDROID_NDK_PATH}/build/tools/make_standalone_toolchain.py --verbose \
--arch ${ANDROID_NDK_ARCH} --install-dir ${NATIVE_LIBS_TOOLCHAIN_PATH} \
--api ${ANDROID_PLATFORM_VER}
find "${PREFIX}/include/" -not -type d > "${NATIVE_LIBS_TOOLCHAIN_PATH}/deletefiles"
}
## This avoid <cmath> include errors due to -isystem and -I ordering issue
delete_copied_includes()
{
cat "${NATIVE_LIBS_TOOLCHAIN_PATH}/deletefiles" | while read delFile ; do
rm "$delFile"
done
}
## More information available at https://gitlab.com/relan/provisioners/merge_requests/1 and http://stackoverflow.com/a/34032216
@ -230,7 +239,8 @@ build_openssl()
# sed -i '/LIBCOMPATVERSIONS=";$(SHLIB_VERSION_HISTORY)" \\/d' Makefile
make -j${HOST_NUM_CPU}
make install
# cp *.so "${SYSROOT}/usr/lib"
rm -f ${PREFIX}/lib/libssl.so*
rm -f ${PREFIX}/lib/libcrypto.so*
cd ..
}
@ -315,9 +325,10 @@ build_restbed()
cd ..
rm -rf restbed-build; mkdir restbed-build ; cd restbed-build
cmake -DBUILD_SSL=OFF -DCMAKE_INSTALL_PREFIX=${PREFIX} -B. -H../restbed
cmake -DBUILD_SSL=OFF -DCMAKE_INSTALL_PREFIX="${PREFIX}" -B. -H../restbed
make -j${HOST_NUM_CPU}
make install
cp "${PREFIX}/library/librestbed.a" "${PREFIX}/lib/"
cd ..
}
@ -329,6 +340,7 @@ build_sqlite
build_sqlcipher
build_libupnp
build_rapidjson
#build_restbed # qmake build it already
build_restbed
delete_copied_includes
echo NATIVE_LIBS_TOOLCHAIN_PATH=${NATIVE_LIBS_TOOLCHAIN_PATH}

View File

@ -881,21 +881,23 @@ rs_jsonapi {
WRAPPERS_INCL_FILE=$$clean_path($${JSONAPI_GENERATOR_OUT}/jsonapi-includes.inl)
WRAPPERS_REG_FILE=$$clean_path($${JSONAPI_GENERATOR_OUT}/jsonapi-wrappers.inl)
restbed.target = $$clean_path($${RESTBED_BUILD_PATH}/library/librestbed.a)
restbed.commands = \
cd $${RS_SRC_PATH};\
git submodule update --init --recommend-shallow supportlibs/restbed;\
cd $${RESTBED_SRC_PATH};\
git submodule update --init --recommend-shallow dependency/asio;\
git submodule update --init --recommend-shallow dependency/catch;\
git submodule update --init --recommend-shallow dependency/kashmir;\
mkdir -p $${RESTBED_BUILD_PATH}; cd $${RESTBED_BUILD_PATH};\
cmake -DCMAKE_CXX_COMPILER=$$QMAKE_CXX -DBUILD_SSL=OFF \
-DCMAKE_INSTALL_PREFIX=. -B. -H$$shell_path($${RESTBED_SRC_PATH});\
make; make install
QMAKE_EXTRA_TARGETS += restbed
libretroshare.depends += restbed
PRE_TARGETDEPS *= $${restbed.target}
no_rs_cross_compiling {
restbed.target = $$clean_path($${RESTBED_BUILD_PATH}/library/librestbed.a)
restbed.commands = \
cd $${RS_SRC_PATH};\
git submodule update --init --recommend-shallow supportlibs/restbed;\
cd $${RESTBED_SRC_PATH};\
git submodule update --init --recommend-shallow dependency/asio;\
git submodule update --init --recommend-shallow dependency/catch;\
git submodule update --init --recommend-shallow dependency/kashmir;\
mkdir -p $${RESTBED_BUILD_PATH}; cd $${RESTBED_BUILD_PATH};\
cmake -DCMAKE_CXX_COMPILER=$$QMAKE_CXX -DBUILD_SSL=OFF \
-DCMAKE_INSTALL_PREFIX=. -B. -H$$shell_path($${RESTBED_SRC_PATH});\
make; make install
QMAKE_EXTRA_TARGETS += restbed
libretroshare.depends += restbed
PRE_TARGETDEPS *= $${restbed.target}
}
PRE_TARGETDEPS *= $${JSONAPI_GENERATOR_EXE}
INCLUDEPATH *= $${JSONAPI_GENERATOR_OUT}
@ -968,12 +970,6 @@ test_bitdht {
################################# Android #####################################
android-* {
## ifaddrs is missing on Android to add them don't use the one from
## https://github.com/morristech/android-ifaddrs
## because it crash, use QNetworkInterface from Qt instead
CONFIG *= qt
QT *= network
DEFINES *= "fopen64=fopen"
DEFINES *= "fseeko64=fseeko"
DEFINES *= "ftello64=ftello"

View File

@ -50,14 +50,17 @@ dLibs =
rs_jsonapi {
RS_SRC_PATH=$$clean_path($${PWD}/../../)
RS_BUILD_PATH=$$clean_path($${OUT_PWD}/../../)
RESTBED_SRC_PATH=$$clean_path($${RS_SRC_PATH}/supportlibs/restbed)
RESTBED_BUILD_PATH=$$clean_path($${RS_BUILD_PATH}/supportlibs/restbed)
INCLUDEPATH *= $$clean_path($${RESTBED_BUILD_PATH}/include/)
QMAKE_LIBDIR *= $$clean_path($${RESTBED_BUILD_PATH}/library/)
# Using sLibs would fail as librestbed.a is generated at compile-time
LIBS *= -L$$clean_path($${RESTBED_BUILD_PATH}/library/) -lrestbed
win32-g++:LIBS += -lwsock32
no_cross_compiling {
RESTBED_SRC_PATH=$$clean_path($${RS_SRC_PATH}/supportlibs/restbed)
RESTBED_BUILD_PATH=$$clean_path($${RS_BUILD_PATH}/supportlibs/restbed)
INCLUDEPATH *= $$clean_path($${RESTBED_BUILD_PATH}/include/)
QMAKE_LIBDIR *= $$clean_path($${RESTBED_BUILD_PATH}/library/)
# Using sLibs would fail as librestbed.a is generated at compile-time
LIBS *= -L$$clean_path($${RESTBED_BUILD_PATH}/library/) -lrestbed
} else:sLibs *= restbed
win32-g++:dLibs *= wsock32
}
linux-* {
@ -79,3 +82,11 @@ LIBS += $$linkStaticLibs(sLibs)
PRE_TARGETDEPS += $$pretargetStaticLibs(sLibs)
LIBS += $$linkDynamicLibs(dLibs)
android-* {
## ifaddrs is missing on Android to add them don't use the one from
## https://github.com/morristech/android-ifaddrs
## because it crash, use QNetworkInterface from Qt instead
CONFIG *= qt
QT *= network
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -1,13 +1,34 @@
<?xml version="1.0"?>
<manifest package="org.retroshare.android.qml_app" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="0.6.4" android:versionCode="1" android:installLocation="auto">
<application android:name="org.qtproject.qt5.android.bindings.QtApplication" android:hardwareAccelerated="true" android:label="RetroShare" android:icon="@drawable/retroshare_128x128">
<activity android:label="">
<meta-data android:name="android.app.lib_name" android:value=""/>
<manifest
package="org.retroshare.service"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="0.6.4" android:versionCode="1"
android:installLocation="auto">
<application android:name="org.qtproject.qt5.android.bindings.QtApplication" android:hardwareAccelerated="true" android:label="RetroShare" android:icon="@drawable/retroshare_service_128x128">
<activity
android:name=".RetroShareServiceControlActivity"
android:label="RetroShare" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name=".BootCompletedReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver android:name=".AppUpdatedReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>
<!-- For adding service(s) please check:
++ https://wiki.qt.io/AndroidServices -->
<service android:name=".RetroShareService" android:process=":rs" android:label="RetroShare Service" android:exported="true">
<service android:name=".RetroShareServiceAndroid" android:process=":rs" android:label="RetroShare Service" android:exported="true">
<!-- android:exported="true" Added to be able to run the service
++ from adb shell
++ android:process=":rs" is needed to force the service to run on
@ -16,16 +37,26 @@
<!-- Qt Application to launch -->
<meta-data android:name="android.app.lib_name" android:value="retroshare-service"/>
<!-- Ministro -->
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
<!-- Deploy Qt libs as part of package -->
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
<!-- Messages maps BEGIN -->
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
<meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
<!-- Messages maps -->
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
<!-- Messages maps END -->
<!-- Messages maps -->
<!-- Background running -->
<meta-data android:name="android.app.background_running" android:value="true"/>
@ -33,7 +64,7 @@
</service>
</application>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="21"/>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="18"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<!-- The following comment will be replaced upon deployment with default

View File

@ -1 +0,0 @@
../../../../../data/128x128/apps/retroshare.png

View File

@ -1 +0,0 @@
../../../../../data/48x48/apps/retroshare.png

View File

@ -0,0 +1 @@
../../../../data/retroshare-service_128x128.png

View File

@ -0,0 +1 @@
../../../../data/retroshare-service_48x48.png

View File

@ -0,0 +1,11 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/startStopButton" android:text="Stop"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -0,0 +1,35 @@
/*
* RetroShare
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.retroshare.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class AppUpdatedReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.i("AppUpdatedReceiver", "onReceive() Restarting RetroShare Service After Update");
RetroShareServiceAndroid.stop(context);
RetroShareServiceAndroid.start(context);
}
}

View File

@ -0,0 +1,34 @@
/*
* RetroShare
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.retroshare.service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootCompletedReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.i("BootCompletedReceiver", "onReceive() Starting RetroShare Service on boot");
RetroShareServiceAndroid.start(context);
}
}

View File

@ -0,0 +1,47 @@
/*
* RetroShare
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.retroshare.service;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import org.qtproject.qt5.android.bindings.QtService;
public class RetroShareServiceAndroid extends QtService
{
public static void start(Context ctx)
{
ctx.startService(new Intent(ctx, RetroShareServiceAndroid.class));
}
public static void stop(Context ctx)
{
ctx.stopService(new Intent(ctx, RetroShareServiceAndroid.class));
}
public static boolean isRunning(Context ctx)
{
ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
if (RetroShareServiceAndroid.class.getName().equals(service.service.getClassName()))
return true;
return false;
}
}

View File

@ -0,0 +1,64 @@
/*
* RetroShare
* Copyright (C) 2016-2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.retroshare.service;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import org.retroshare.service.R;
public class RetroShareServiceControlActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.retroshare_service_control_layout);
final Button button = (Button) findViewById(R.id.startStopButton);
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if (RetroShareServiceAndroid.isRunning(RetroShareServiceControlActivity.this))
{
RetroShareServiceAndroid.stop(RetroShareServiceControlActivity.this);
button.setText("Start");
}
else
{
RetroShareServiceAndroid.start(RetroShareServiceControlActivity.this);
button.setText("Stop");
}
}
});
super.onCreate(savedInstanceState);
}
@Override
public void onResume()
{
super.onResume();
final Button button = (Button) findViewById(R.id.startStopButton);
button.setText(RetroShareServiceAndroid.isRunning(this) ? "Stop" : "Start");
}
}

View File

@ -21,6 +21,10 @@
#include <QObject>
#include <QStringList>
#ifdef __ANDROID__
# include <QAndroidService>
#endif // def __ANDROID__
#include "retroshare/rsinit.h"
#include "retroshare/rsiface.h"
@ -36,9 +40,10 @@ int main(int argc, char* argv[])
{
#ifdef __ANDROID__
AndroidStdIOCatcher dbg; (void) dbg;
#endif
QAndroidService app(argc, argv);
#else // def __ANDROID__
QCoreApplication app(argc, argv);
#endif // def __ANDROID__
signal(SIGINT, QCoreApplication::exit);
signal(SIGTERM, QCoreApplication::exit);

View File

@ -10,6 +10,8 @@ QT -= gui
SOURCES += retroshare-service.cc
android-* {
QT += androidextras
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
DISTFILES += android/AndroidManifest.xml \
@ -23,6 +25,7 @@ android-* {
android/gradlew.bat
}
appimage {
icon_files.path = "$${PREFIX}/share/icons/hicolor/scalable/"
icon_files.files = ../data/retroshare-service.svg