Skip to content

Commit

Permalink
revert switching from JNI to binary
Browse files Browse the repository at this point in the history
Signed-off-by: r4sas <[email protected]>
  • Loading branch information
r4sas committed Jul 29, 2024
1 parent 8347c04 commit 503f8a0
Show file tree
Hide file tree
Showing 24 changed files with 686 additions and 450 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: |
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/23.2.8568313
pushd binary/jni
./build.sh -md
./build.sh
popd
- name: Build with Gradle
run: ./gradlew --no-daemon assembleDebug
Expand All @@ -45,11 +45,11 @@ jobs:
run: export JAVA_HOME=$JAVA_HOME_11_X64
- name: Install required Android SDK packages
run: $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "cmake;3.22.1" "ndk;23.2.8568313"
- name: Build binaries with NDK
- name: Build binary with NDK
run: |
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/23.2.8568313
pushd binary/jni
./build.sh
./build.sh -b
popd
- name: Create package with built binaries
run: |
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ unzip commandlinetools-linux-8092744_latest.zip

```bash
git clone --recurse-submodules https://github.com/PurpleI2P/i2pd-android.git
cd i2pd-android
```

### Compile application
Expand All @@ -54,8 +53,10 @@ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export ANDROID_HOME=/opt/android-sdk
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/23.2.8568313

pushd binary/jni
./build.sh -md
pushd app/jni
./build_boost.sh
./build_openssl.sh
./build_miniupnpc.sh
popd

gradle clean assembleDebug
Expand Down
17 changes: 12 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ android {
targetSdkVersion 33
// TODO: 24?
minSdkVersion 16
versionCode 2530000
versionName "2.53.0"
versionCode 2530010
versionName "2.53.0.1"
archivesBaseName += "-$versionName"
ndkVersion "23.2.8568313"

Expand All @@ -40,6 +40,13 @@ android {
abiFilters "arm64-v8a"
abiFilters "x86_64"
}

externalNativeBuild {
ndkBuild {
arguments "NDK_MODULE_PATH:=${rootProject.projectDir}/binary/jni"
arguments "-j${Runtime.getRuntime().availableProcessors()}"
}
}
}

splits {
Expand Down Expand Up @@ -71,9 +78,9 @@ android {
}
}

sourceSets {
main {
jniLibs.srcDir file("${rootProject.projectDir}/binary/libs")
externalNativeBuild {
ndkBuild {
path "${rootProject.projectDir}/app/jni/Android.mk"
}
}

Expand Down
80 changes: 80 additions & 0 deletions app/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := i2pd
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_C_INCLUDES += $(IFADDRS_PATH) $(LIB_SRC_PATH) $(LIB_CLIENT_SRC_PATH) $(LANG_SRC_PATH) $(DAEMON_SRC_PATH)
LOCAL_STATIC_LIBRARIES := \
boost_system \
boost_date_time \
boost_filesystem \
boost_program_options \
crypto \
ssl \
miniupnpc
LOCAL_LDLIBS := -lz

LOCAL_SRC_FILES := \
DaemonAndroid.cpp \
i2pd_android.cpp \
$(IFADDRS_PATH)/ifaddrs.cpp \
$(IFADDRS_PATH)/bionic_netlink.cpp \
$(wildcard $(LIB_SRC_PATH)/*.cpp) \
$(wildcard $(LIB_CLIENT_SRC_PATH)/*.cpp) \
$(wildcard $(LANG_SRC_PATH)/*.cpp) \
$(DAEMON_SRC_PATH)/Daemon.cpp \
$(DAEMON_SRC_PATH)/UPnP.cpp \
$(DAEMON_SRC_PATH)/HTTPServer.cpp \
$(DAEMON_SRC_PATH)/I2PControl.cpp \
$(DAEMON_SRC_PATH)/I2PControlHandlers.cpp

include $(BUILD_SHARED_LIBRARY)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := boost_system
LOCAL_SRC_FILES := $(BOOST_PATH)/build/out/$(TARGET_ARCH_ABI)/lib/libboost_system.a
LOCAL_EXPORT_C_INCLUDES := $(BOOST_PATH)/build/out/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_STATIC_LIBRARY)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := boost_date_time
LOCAL_SRC_FILES := $(BOOST_PATH)/build/out/$(TARGET_ARCH_ABI)/lib/libboost_date_time.a
LOCAL_EXPORT_C_INCLUDES := $(BOOST_PATH)/build/out/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_STATIC_LIBRARY)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := boost_filesystem
LOCAL_SRC_FILES := $(BOOST_PATH)/build/out/$(TARGET_ARCH_ABI)/lib/libboost_filesystem.a
LOCAL_EXPORT_C_INCLUDES := $(BOOST_PATH)/build/out/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_STATIC_LIBRARY)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := boost_program_options
LOCAL_SRC_FILES := $(BOOST_PATH)/build/out/$(TARGET_ARCH_ABI)/lib/libboost_program_options.a
LOCAL_EXPORT_C_INCLUDES := $(BOOST_PATH)/build/out/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_STATIC_LIBRARY)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := $(OPENSSL_PATH)/out/$(TARGET_ARCH_ABI)/lib/libcrypto.a
LOCAL_EXPORT_C_INCLUDES := $(OPENSSL_PATH)/out/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_STATIC_LIBRARY)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := $(OPENSSL_PATH)/out/$(TARGET_ARCH_ABI)/lib/libssl.a
LOCAL_EXPORT_C_INCLUDES := $(OPENSSL_PATH)/out/$(TARGET_ARCH_ABI)/include
LOCAL_STATIC_LIBRARIES := crypto
include $(PREBUILT_STATIC_LIBRARY)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := miniupnpc
LOCAL_SRC_FILES := $(MINIUPNP_PATH)/miniupnpc/out/$(TARGET_ARCH_ABI)/lib/libminiupnpc.a
LOCAL_EXPORT_C_INCLUDES := $(MINIUPNP_PATH)/miniupnpc/out/$(TARGET_ARCH_ABI)/include
include $(PREBUILT_STATIC_LIBRARY)
23 changes: 23 additions & 0 deletions app/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
NDK_TOOLCHAIN_VERSION := clang
APP_STL := c++_static

# Enable c++17 extensions in source code
APP_CPPFLAGS += -std=c++17 -fexceptions -frtti

APP_CPPFLAGS += -DANDROID -D__ANDROID__ -DUSE_UPNP -Wno-deprecated-declarations
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
APP_CPPFLAGS += -DANDROID_ARM7A
endif

IFADDRS_PATH = $(NDK_MODULE_PATH)/android-ifaddrs
BOOST_PATH = $(NDK_MODULE_PATH)/boost
MINIUPNP_PATH = $(NDK_MODULE_PATH)/miniupnp
OPENSSL_PATH = $(NDK_MODULE_PATH)/openssl

# don't change me
I2PD_SRC_PATH = $(NDK_MODULE_PATH)/i2pd

LIB_SRC_PATH = $(I2PD_SRC_PATH)/libi2pd
LIB_CLIENT_SRC_PATH = $(I2PD_SRC_PATH)/libi2pd_client
LANG_SRC_PATH = $(I2PD_SRC_PATH)/i18n
DAEMON_SRC_PATH = $(I2PD_SRC_PATH)/daemon
138 changes: 138 additions & 0 deletions app/jni/DaemonAndroid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright (c) 2013-2022, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
* See full license text in LICENSE file at top of project tree
*/

#include <iostream>
#include <chrono>
#include <thread>
#include <exception>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/exception_ptr.hpp>
//#include "mainwindow.h"
#include "FS.h"
#include "DaemonAndroid.h"
#include "Daemon.h"
#include "I18N.h"

namespace i2p
{
namespace android
{
std::string dataDir = "";
std::string language = "";

DaemonAndroidImpl::DaemonAndroidImpl ()
{
}

DaemonAndroidImpl::~DaemonAndroidImpl ()
{
}

bool DaemonAndroidImpl::init(int argc, char* argv[])
{
return Daemon.init(argc, argv);
}

void DaemonAndroidImpl::start()
{
Daemon.start();
}

void DaemonAndroidImpl::stop()
{
Daemon.stop();
}

void DaemonAndroidImpl::restart()
{
stop();
start();
}

void DaemonAndroidImpl::setDataDir(std::string path)
{
Daemon.setDataDir(path);
}

static DaemonAndroidImpl daemon;
static char* argv[1]={strdup("tmp")};
/**
* returns error details if failed
* returns "ok" if daemon initialized and started okay
*/
std::string start(/*int argc, char* argv[]*/)
{
try
{
{
// make sure assets are ready before proceed
i2p::fs::DetectDataDir(dataDir, false);
int numAttempts = 0;
do
{
if (i2p::fs::Exists (i2p::fs::DataDirPath("assets.ready"))) break; // assets ready
numAttempts++;
std::this_thread::sleep_for (std::chrono::seconds(1)); // otherwise wait for 1 more second
}
while (numAttempts <= 10); // 10 seconds max

// Set application directory
daemon.setDataDir(dataDir);

bool daemonInitSuccess = daemon.init(1, argv);
if(!daemonInitSuccess)
{
return "Daemon init failed";
}

// Set webconsole language from application
i2p::i18n::SetLanguage(language);

daemon.start();
}
}
catch (boost::exception& ex)
{
std::stringstream ss;
ss << boost::diagnostic_information(ex);
return ss.str();
}
catch (std::exception& ex)
{
std::stringstream ss;
ss << ex.what();
return ss.str();
}
catch(...)
{
return "unknown exception";
}
return "ok";
}

void stop()
{
daemon.stop();
}

void SetDataDir(std::string jdataDir)
{
dataDir = jdataDir;
}

std::string GetDataDir(void)
{
return dataDir;
}

void SetLanguage(std::string jlanguage)
{
language = jlanguage;
}
}
}
53 changes: 53 additions & 0 deletions app/jni/DaemonAndroid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2013-2022, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
* See full license text in LICENSE file at top of project tree
*/

#ifndef DAEMON_ANDROID_H
#define DAEMON_ANDROID_H

#include <string>

namespace i2p
{
namespace android
{
class DaemonAndroidImpl
{
public:

DaemonAndroidImpl ();
~DaemonAndroidImpl ();

/**
* @return success
*/
bool init (int argc, char* argv[]);
void start ();
void stop ();
void restart ();

void setDataDir (std::string path);
};

/**
* returns "ok" if daemon init failed
* returns errinfo if daemon initialized and started okay
*/
std::string start ();

void stop ();

// set datadir received from jni
void SetDataDir (std::string jdataDir);
// get datadir
std::string GetDataDir (void);
// set webconsole language
void SetLanguage (std::string jlanguage);
}
}

#endif // DAEMON_ANDROID_H
Loading

0 comments on commit 503f8a0

Please sign in to comment.