Skip to content

Commit 9650dd3

Browse files
committed
Add C++ version GenieAPIService
1 parent 816b0c8 commit 9650dd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2608
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import org.gradle.api.tasks.Copy
2+
import java.io.File
3+
4+
val sourceFiles = listOf(
5+
file("..\\..\\Service\\libs\\arm64-v8a\\libJNIGenieAPIService.so"),
6+
file("..\\..\\Service\\libs\\arm64-v8a\\libGenie.so"),
7+
file("..\\..\\Service\\libs\\arm64-v8a\\libQnnHtp.so"),
8+
file("..\\..\\Service\\libs\\arm64-v8a\\libQnnHtpNetRunExtensions.so"),
9+
file("..\\..\\Service\\libs\\arm64-v8a\\libQnnHtpPrepare.so"),
10+
file("..\\..\\Service\\libs\\arm64-v8a\\libQnnHtpV79Skel.so"),
11+
file("..\\..\\Service\\libs\\arm64-v8a\\libQnnHtpV79Stub.so"),
12+
file("..\\..\\Service\\libs\\arm64-v8a\\libQnnSystem.so"),
13+
)
14+
15+
val libsDir = file("libs/arm64-v8a")
16+
17+
println("sourceFiles path: ${sourceFiles}")
18+
println("libsDir path: ${libsDir.absolutePath}")
19+
20+
val copyHttpServiceTask = tasks.register<Copy>("copyHttpService") {
21+
from(sourceFiles)
22+
into(libsDir)
23+
}
24+
25+
tasks.preBuild {
26+
dependsOn(copyHttpServiceTask)
27+
}
28+
29+
plugins {
30+
alias(libs.plugins.android.application)
31+
}
32+
33+
android {
34+
namespace = "com.example.genieapiservice"
35+
compileSdk = 35
36+
37+
lint {
38+
baseline = file("lint-baseline.xml")
39+
}
40+
defaultConfig {
41+
applicationId = "com.example.genieapiservice"
42+
minSdk = 28
43+
targetSdk = 28
44+
versionCode = 1
45+
versionName = "1.0"
46+
47+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
48+
externalNativeBuild {
49+
cmake {
50+
cppFlags += "-std=c++14"
51+
arguments("-DANDROID_ABI=arm64-v8a")
52+
}
53+
}
54+
ndk {
55+
abiFilters.add("arm64-v8a")
56+
}
57+
sourceSets {
58+
getByName("main") {
59+
jniLibs.srcDir("libs")
60+
}
61+
}
62+
}
63+
64+
buildTypes {
65+
release {
66+
isMinifyEnabled = false
67+
proguardFiles(
68+
getDefaultProguardFile("proguard-android-optimize.txt"),
69+
"proguard-rules.pro"
70+
)
71+
}
72+
}
73+
74+
compileOptions {
75+
sourceCompatibility = JavaVersion.VERSION_11
76+
targetCompatibility = JavaVersion.VERSION_11
77+
}
78+
79+
externalNativeBuild {
80+
cmake {
81+
path = file("src/main/cpp/CMakeLists.txt")
82+
version = "3.22.1"
83+
}
84+
}
85+
86+
buildFeatures {
87+
viewBinding = true
88+
}
89+
90+
packaging {
91+
jniLibs.useLegacyPackaging = true
92+
}
93+
}
94+
95+
dependencies {
96+
97+
implementation(libs.appcompat)
98+
implementation(libs.material)
99+
implementation(libs.constraintlayout)
100+
testImplementation(libs.junit)
101+
androidTestImplementation(libs.ext.junit)
102+
androidTestImplementation(libs.espresso.core)
103+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<issues format="6" by="lint 8.9.1" type="baseline" client="gradle" dependencies="false" name="AGP (8.9.1)" variant="fatal" version="8.9.1">
3+
4+
<issue
5+
id="ExpiredTargetSdkVersion"
6+
message="Google Play requires that apps target API level 33 or higher."
7+
errorLine1=" targetSdk = 28"
8+
errorLine2=" ~~~~~~~~~~~~~~">
9+
<location
10+
file="build.gradle.kts"
11+
line="42"
12+
column="9"/>
13+
</issue>
14+
15+
</issues>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.genieapiservice;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.example.genieapiservice", appContext.getPackageName());
25+
}
26+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
8+
<uses-permission android:name="android.permission.INTERNET" />
9+
10+
<application
11+
android:largeHeap="true"
12+
android:allowBackup="true"
13+
android:dataExtractionRules="@xml/data_extraction_rules"
14+
android:fullBackupContent="@xml/backup_rules"
15+
android:icon="@mipmap/ic_launcher"
16+
android:label="@string/app_name"
17+
android:roundIcon="@mipmap/ic_launcher_round"
18+
android:supportsRtl="true"
19+
android:usesCleartextTraffic="true"
20+
android:theme="@style/Theme.GenieAPIService"
21+
tools:targetApi="31">
22+
<activity
23+
android:name=".MainActivity"
24+
android:exported="true">
25+
<intent-filter>
26+
<action android:name="android.intent.action.MAIN" />
27+
28+
<category android:name="android.intent.category.LAUNCHER" />
29+
</intent-filter>
30+
</activity>
31+
32+
<uses-native-library
33+
android:name="libadsprpc.so"
34+
android:required="false" />
35+
<uses-native-library
36+
android:name="libcdsprpc.so"
37+
android:required="false" />
38+
</application>
39+
40+
</manifest>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# For more information about using CMake with Android Studio, read the
2+
# documentation: https://d.android.com/studio/projects/add-native-code.html.
3+
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
4+
5+
# Sets the minimum CMake version required for this project.
6+
cmake_minimum_required(VERSION 3.22.1)
7+
8+
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
9+
# Since this is the top level CMakeLists.txt, the project name is also accessible
10+
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
11+
# build script scope).
12+
project("genieapiservice")
13+
14+
# Creates and names a library, sets it as either STATIC
15+
# or SHARED, and provides the relative paths to its source code.
16+
# You can define multiple libraries, and CMake builds them for you.
17+
# Gradle automatically packages shared libraries with your APK.
18+
#
19+
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
20+
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
21+
# is preferred for the same purpose.
22+
#
23+
# In order to load a library into your app from Java/Kotlin, you must call
24+
# System.loadLibrary() and pass the name of the library defined here;
25+
# for GameActivity/NativeActivity derived applications, the same library name must be
26+
# used in the AndroidManifest.xml file.
27+
add_library(${CMAKE_PROJECT_NAME} SHARED
28+
# List C/C++ source files with relative paths to this CMakeLists.txt.
29+
native-lib.cpp)
30+
31+
# Specifies libraries CMake should link to your target library. You
32+
# can link libraries from various origins, such as libraries defined in this
33+
# build script, prebuilt third-party libraries, or Android system libraries.
34+
target_link_libraries(${CMAKE_PROJECT_NAME}
35+
# List libraries link to the target library
36+
android
37+
log)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <jni.h>
2+
#include <string>
3+
4+
extern "C" JNIEXPORT jstring JNICALL
5+
Java_com_example_genieapiservice_MainActivity_stringFromJNI(
6+
JNIEnv* env,
7+
jobject /* this */) {
8+
std::string hello = "<br><br><br><br><br><br><br><br><br><br><h1>Initializing Genie Service...</h1>";
9+
return env->NewStringUTF(hello.c_str());
10+
}

0 commit comments

Comments
 (0)