ktaglib: import taglib into project
This is getting out of hand. Anything for speed.
This commit is contained in:
parent
d3f75439fc
commit
1c85dc96e0
15 changed files with 223 additions and 1 deletions
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -1,3 +1,7 @@
|
|||
[submodule "media"]
|
||||
path = media
|
||||
url = https://github.com/OxygenCobalt/media.git
|
||||
[submodule "taglib"]
|
||||
path = ktaglib/src/main/cpp/taglib
|
||||
url = https://github.com/taglib/taglib.git
|
||||
tag = v2.0.2
|
||||
|
|
|
@ -137,6 +137,9 @@ dependencies {
|
|||
implementation project(":media-lib-decoder-ffmpeg")
|
||||
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.1.3"
|
||||
|
||||
// Taglib
|
||||
implementation project(":ktaglib")
|
||||
|
||||
// Image loading
|
||||
implementation 'io.coil-kt.coil3:coil-core:3.0.2'
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ plugins {
|
|||
id "org.jetbrains.kotlin.android" version "$kotlin_version" apply false
|
||||
id "com.google.devtools.ksp" version '2.0.21-1.0.25' apply false
|
||||
id "com.diffplug.spotless" version "6.25.0" apply false
|
||||
id 'com.android.library' version '8.7.2' apply false
|
||||
}
|
||||
|
||||
tasks.register('clean', Delete) {
|
||||
|
|
1
ktaglib/.gitignore
vendored
Normal file
1
ktaglib/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build
|
52
ktaglib/build.gradle
Normal file
52
ktaglib/build.gradle
Normal file
|
@ -0,0 +1,52 @@
|
|||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.example.ktaglib'
|
||||
compileSdk 34
|
||||
ndkVersion "26.3.11579264"
|
||||
|
||||
defaultConfig {
|
||||
minSdk 24
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
cppFlags ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "src/main/cpp/CMakeLists.txt"
|
||||
version "3.22.1"
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_11
|
||||
targetCompatibility JavaVersion.VERSION_11
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '11'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.15.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.7.0'
|
||||
implementation 'com.google.android.material:material:1.12.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
|
||||
}
|
0
ktaglib/consumer-rules.pro
Normal file
0
ktaglib/consumer-rules.pro
Normal file
21
ktaglib/proguard-rules.pro
vendored
Normal file
21
ktaglib/proguard-rules.pro
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
4
ktaglib/src/main/AndroidManifest.xml
Normal file
4
ktaglib/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
57
ktaglib/src/main/cpp/CMakeLists.txt
Normal file
57
ktaglib/src/main/cpp/CMakeLists.txt
Normal file
|
@ -0,0 +1,57 @@
|
|||
# For more information about using CMake with Android Studio, read the
|
||||
# documentation: https://d.android.com/studio/projects/add-native-code.html.
|
||||
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
|
||||
|
||||
# Sets the minimum CMake version required for this project.
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
|
||||
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
|
||||
# Since this is the top level CMakeLists.txt, the project name is also accessible
|
||||
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
|
||||
# build script scope).
|
||||
project("ktaglib")
|
||||
|
||||
# Creates and names a library, sets it as either STATIC
|
||||
# or SHARED, and provides the relative paths to its source code.
|
||||
# You can define multiple libraries, and CMake builds them for you.
|
||||
# Gradle automatically packages shared libraries with your APK.
|
||||
#
|
||||
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
|
||||
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
|
||||
# is preferred for the same purpose.
|
||||
#
|
||||
# In order to load a library into your app from Java/Kotlin, you must call
|
||||
# System.loadLibrary() and pass the name of the library defined here;
|
||||
# for GameActivity/NativeActivity derived applications, the same library name must be
|
||||
# used in the AndroidManifest.xml file.
|
||||
set(taglib_location "${CMAKE_CURRENT_SOURCE_DIR}/taglib")
|
||||
set(taglib_pkg "${taglib_location}/android-libs/${ANDROID_ABI}")
|
||||
set(taglib_lib "${taglib_pkg}/lib")
|
||||
set(taglib_include "${taglib_pkg}/include")
|
||||
|
||||
set(taglib_file_name libtag.a)
|
||||
set(taglib_file_path ${taglib_lib}/${taglib_file_name})
|
||||
set(taglib_lib_name, "taglib")
|
||||
add_library(
|
||||
"taglib"
|
||||
STATIC
|
||||
IMPORTED)
|
||||
set_target_properties(
|
||||
"taglib" PROPERTIES
|
||||
IMPORTED_LOCATION
|
||||
${taglib_file_path}
|
||||
INTERFACE_INCLUDE_DIRECTORIES
|
||||
${taglib_include})
|
||||
|
||||
add_library(${CMAKE_PROJECT_NAME} SHARED
|
||||
# List C/C++ source files with relative paths to this CMakeLists.txt.
|
||||
ktaglib.cpp)
|
||||
|
||||
# Specifies libraries CMake should link to your target library. You
|
||||
# can link libraries from various origins, such as libraries defined in this
|
||||
# build script, prebuilt third-party libraries, or Android system libraries.
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
# List libraries link to the target library
|
||||
android
|
||||
log
|
||||
taglib)
|
15
ktaglib/src/main/cpp/android.toolchain.cmake
Normal file
15
ktaglib/src/main/cpp/android.toolchain.cmake
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Define the minimum CMake version and project name
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
|
||||
# Set the Android NDK path
|
||||
option(ANDROID_NDK_PATH "Path to Android NDK Install. Should be same version specified in gradle." REQUIRED)
|
||||
|
||||
# Specify the target Android API level
|
||||
set(ANDROID_PLATFORM android-24)
|
||||
|
||||
# Define the toolchain
|
||||
set(CMAKE_SYSTEM_NAME Android)
|
||||
set(CMAKE_ANDROID_ARCH_ABI ${ANDROID_ABI})
|
||||
set(CMAKE_ANDROID_NDK ${ANDROID_NDK_PATH})
|
||||
set(CMAKE_ANDROID_STL_TYPE c++_static)
|
||||
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang)
|
36
ktaglib/src/main/cpp/build_taglib.sh
Normal file
36
ktaglib/src/main/cpp/build_taglib.sh
Normal file
|
@ -0,0 +1,36 @@
|
|||
set -e
|
||||
TAGLIB_SRC_DIR=$(pwd)/taglib
|
||||
TAGLIB_DST_DIR=$(pwd)/taglib/build
|
||||
TAGLIB_PKG_DIR=$(pwd)/taglib/pkg
|
||||
NDK_TOOLCHAIN=$(pwd)/android.toolchain.cmake
|
||||
NDK_PATH=$1
|
||||
echo "Taglib source is at $TAGLIB_SRC_DIR"
|
||||
echo "Taglib build is at $TAGLIB_DST_DIR"
|
||||
echo "Taglib package is at $TAGLIB_PKG_DIR"
|
||||
echo "NDK toolchain is at $NDK_TOOLCHAIN"
|
||||
echo "NDK path is at $NDK_PATH"
|
||||
|
||||
X86_ARCH=x86
|
||||
X86_64_ARCH=x86_64
|
||||
ARMV7_ARCH=armeabi-v7a
|
||||
ARMV8_ARCH=arm64-v8a
|
||||
|
||||
build_for_arch() {
|
||||
local ARCH=$1
|
||||
local DST_DIR=$TAGLIB_DST_DIR/$ARCH
|
||||
local PKG_DIR=$TAGLIB_PKG_DIR/$ARCH
|
||||
|
||||
pushd $TAGLIB_SRC_DIR
|
||||
cmake -B $DST_DIR -DANDROID_NDK_PATH=${NDK_PATH} -DCMAKE_TOOLCHAIN_FILE=${NDK_TOOLCHAIN} \
|
||||
-DANDROID_ABI=$ARCH -DBUILD_SHARED_LIBS=OFF -DVISIBILITY_HIDDEN=ON -DBUILD_TESTING=OFF \
|
||||
-DBUILD_EXAMPLES=OFF -DBUILD_BINDINGS=OFF -DWITH_ZLIB=OFF -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build $DST_DIR --config Release
|
||||
popd
|
||||
|
||||
cmake --install $DST_DIR --config Release --prefix $PKG_DIR --strip
|
||||
}
|
||||
|
||||
build_for_arch $X86_ARCH
|
||||
build_for_arch $X86_64_ARCH
|
||||
build_for_arch $ARMV7_ARCH
|
||||
build_for_arch $ARMV8_ARCH
|
12
ktaglib/src/main/cpp/ktaglib.cpp
Normal file
12
ktaglib/src/main/cpp/ktaglib.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <jni.h>
|
||||
#include <string>
|
||||
|
||||
#include "taglib/tag.h"
|
||||
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_com_example_ktaglib_NativeLib_stringFromJNI(
|
||||
JNIEnv* env,
|
||||
jobject /* this */) {
|
||||
std::string hello = "Hello from C++";
|
||||
return env->NewStringUTF(hello.c_str());
|
||||
}
|
1
ktaglib/src/main/cpp/taglib
Submodule
1
ktaglib/src/main/cpp/taglib
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 225c73e1816c3200c67703557972586e287fa665
|
14
ktaglib/src/main/java/com/example/ktaglib/KTagLib.kt
Normal file
14
ktaglib/src/main/java/com/example/ktaglib/KTagLib.kt
Normal file
|
@ -0,0 +1,14 @@
|
|||
package com.example.ktaglib
|
||||
|
||||
object KTagLib {
|
||||
// Used to load the 'ktaglib' library on application startup.
|
||||
init {
|
||||
System.loadLibrary("ktaglib")
|
||||
}
|
||||
|
||||
/**
|
||||
* A native method that is implemented by the 'ktaglib' native library,
|
||||
* which is packaged with this application.
|
||||
*/
|
||||
external fun stringFromJNI(): String
|
||||
}b
|
|
@ -20,3 +20,4 @@ apply from: file("media/core_settings.gradle")
|
|||
|
||||
rootProject.name = "Auxio"
|
||||
include ':app'
|
||||
include ':ktaglib'
|
||||
|
|
Loading…
Reference in a new issue