Skip to content

Commit

Permalink
Adjust JNI lib loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielku15 committed Dec 23, 2023
1 parent e50e838 commit 34b2495
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 212 deletions.
12 changes: 5 additions & 7 deletions build/Build.Java.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,24 @@ string JavaVersion
get
{
string semVer;
if (IsLocalBuild)
if (IsReleaseBuild)
{
semVer = $"{VersionInfo.FileVersion.ToString(3)}-LOCAL";
semVer = $"{VersionInfo.FileVersion.ToString(3)}";
}
else if (!IsReleaseBuild)
else if (IsLocalBuild)
{
semVer = $"{VersionInfo.FileVersion.ToString(3)}-SNAPSHOT";
semVer = $"{VersionInfo.FileVersion.ToString(3)}-LOCAL";
}
else
{
semVer = $"{VersionInfo.FileVersion.ToString(3)}";
semVer = $"{VersionInfo.FileVersion.ToString(3)}-SNAPSHOT";
}

return semVer;
}
}

public Target JavaPublish => _ => _
.DependsOn(PrepareGitHubArtifacts)
.Requires(() => IsGitHubActions)
.Executes(() =>
{
// workaround until we know how to upload existing maven packages
Expand Down
1 change: 1 addition & 0 deletions build/Build.Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ Dictionary<string, string> PrepareNativeBuild(Variant variant)
if (TargetOs == TargetOperatingSystem.Android)
{
gnArgs["ndk"] = NdkPath;
AppendToFlagList(gnArgs, "extra_ldflags", $"'-llog'");
}

gnArgs["target_os"] = TargetOs.SkiaTargetOs;
Expand Down
2 changes: 1 addition & 1 deletion lib/java/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/java/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 49 additions & 14 deletions lib/java/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,38 +1,73 @@
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
import com.android.build.gradle.internal.tasks.factory.dependsOn

plugins {
id("java-library")
id("com.android.library")
`maven-publish`
signing
}

java {
toolchain{
languageVersion.set(JavaLanguageVersion.of(17))
}
withSourcesJar()
withJavadocJar()
dependencies {
implementation(project(":main"))
}

tasks.jar {
archiveBaseName = "alphaSkia-android"
tasks.register<Copy>("copyJniForAndroid") {
// https://developer.android.com/studio/projects/gradle-external-native-builds#jniLibs
// https://developer.android.com/ndk/guides/abis#sa

into("native/android-x64/") {
into("src/main/jniLibs/x86_64") {
from(rootProject.projectDir.resolve("../../dist/libalphaskiajni-android-x64-jni/")) {
include("*.so")
}
}
into("native/android-x86/") {
into("src/main/jniLibs/x86") {
from(rootProject.projectDir.resolve("../../dist/libalphaskiajni-android-x86-jni/")) {
include("*.so")
}
}
into("native/android-arm64/") {
into("src/main/jniLibs/arm64-v8a") {
from(rootProject.projectDir.resolve("../../dist/libalphaskiajni-android-arm64-jni/")) {
include("*.so")
}
}
into("native/android-arm/") {
into("src/main/jniLibs/armeabi-v7a") {
from(rootProject.projectDir.resolve("../../dist/libalphaskiajni-android-arm-jni/")) {
include("*.so")
}
}
}

destinationDir = projectDir
}
tasks.preBuild.dependsOn("copyJniForAndroid")


android {
namespace = "net.alphatab.alphaskia.android"
compileSdk = 34

defaultConfig {
minSdk = 26
ndk {
abiFilters += listOf("x86", "x86_64", "armeabi-v7a", "arm64-v8a")
}
setProperty("archivesBaseName", "alphaSkia-android")
}

buildTypes {
release {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}

Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
package alphaTab.alphaSkia;

/**
* This class contains the information about the Android runtime dependencies to use with AlphaSkiaPlatform.
* The alphaSkia initializer for Android.
*/
public final class AlphaSkiaAndroid {
/**
* The native libraries needed to run alphaSkia.
*/
public static final String[] libraries = {
"/native/android-" + getCurrentArchitecture() + "/libalphaskiajni.so"
};
public class AlphaSkiaAndroid extends AlphaSkiaPlatform {
public static final AlphaSkiaAndroid INSTANCE = new AlphaSkiaAndroid();

private static String getCurrentArchitecture() {
var jarch = System.getProperty("os.arch");
return switch (jarch) {
case "x86", "i368", "i486", "i586", "i686" -> "x86";
case "x86_64", "amd64" -> "x64";
case "arm" -> "arm";
case "aarch64" -> "arm64";
default -> jarch;
};
@Override
public void inititalize() {
System.loadLibrary("alphaskiajni");
setNativeLibLoaded();
}

private AlphaSkiaAndroid() {}
}

137 changes: 67 additions & 70 deletions lib/java/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import java.io.FileInputStream
import java.util.*

buildscript {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}

plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
id("com.android.library") version "8.1.0" apply false
}

var sonatypeSigningKeyId = ""
Expand Down Expand Up @@ -76,42 +69,17 @@ group = "net.alphatab"
version = libVersion

subprojects {
apply<JavaLibraryPlugin>()
apply<MavenPublishPlugin>()
apply(plugin = "maven-publish")
apply(plugin = "signing")

group = "net.alphatab"
version = libVersion

repositories {
google()
mavenCentral()
}

configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
withSourcesJar()
withJavadocJar()
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

tasks.withType<Test> {
defaultCharacterEncoding = "UTF-8"
}

tasks.withType<JavaExec> {
defaultCharacterEncoding = "UTF-8"
}

tasks.withType<Javadoc> {
options.encoding = "UTF-8"
}
group = "net.alphatab"
version = libVersion

configure<SigningExtension> {
if (sonatypeSigningKeyId.isNotBlank() && sonatypeSigningKey.isNotBlank() && sonatypeSigningPassword.isNotBlank()) {
Expand All @@ -122,46 +90,75 @@ subprojects {
}
}

configure<PublishingExtension> {
repositories {
maven {
name = "DistPath"
url = rootProject.projectDir.resolve("dist").toURI()
if (!this.project.name.contains("android")) {
apply<JavaLibraryPlugin>()

configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
withSourcesJar()
withJavadocJar()
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

tasks.withType<Test> {
defaultCharacterEncoding = "UTF-8"
}

tasks.withType<JavaExec> {
defaultCharacterEncoding = "UTF-8"
}

publications {
// this publication builds the library and is meant to publish to the local dist folder
create<MavenPublication>("mavenJava") {
from(components["java"])
afterEvaluate {
artifactId = tasks.withType<Jar>().first().archiveBaseName.get()
pom {
name = tasks.withType<Jar>().first().archiveBaseName.get()
description = libDescription
url = libProjectUrl
licenses {
license {
name = libLicenseSpdx
url = libLicenseUrl
tasks.withType<Javadoc> {
options.encoding = "UTF-8"
}
}

afterEvaluate {
configure<PublishingExtension> {
repositories {
maven {
name = "DistPath"
url = rootProject.projectDir.resolve("dist").toURI()
}
}

publications {
create<MavenPublication>("mavenJava") {
afterEvaluate {
from(components.findByName("java") ?: components["release"])
artifactId = tasks.withType<Jar>().firstOrNull()?.archiveBaseName?.get()
pom {
name = artifactId
description = libDescription
url = libProjectUrl
licenses {
license {
name = libLicenseSpdx
url = libLicenseUrl
}
}
}
developers {
developer {
id = libAuthorId
name = libAuthorName
organization = libCompany
organizationUrl = libOrgUrl
developers {
developer {
id = libAuthorId
name = libAuthorName
organization = libCompany
organizationUrl = libOrgUrl
}
}
scm {
url = libGitUrlHttp
connection = "scm:git:$libGitUrlGit"
developerConnection = "scm:git:$libGitUrlGit"
}
issueManagement {
system = "GitHub"
url = libIssuesUrl
}
}
scm {
url = libGitUrlHttp
connection = "scm:git:$libGitUrlGit"
developerConnection = "scm:git:$libGitUrlGit"
}
issueManagement {
system = "GitHub"
url = libIssuesUrl
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions lib/java/linux/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ plugins {
signing
}

dependencies {
implementation(project(":main"))
}


java {
toolchain{
languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
25 changes: 11 additions & 14 deletions lib/java/linux/src/main/java/alphaTab/alphaSkia/AlphaSkiaLinux.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package alphaTab.alphaSkia;

/**
* This class contains the information about the Linux runtime dependencies to use with AlphaSkiaPlatform.
* The alphaSkia initializer for Linux.
*/
public class AlphaSkiaLinux {
public class AlphaSkiaLinux extends AlphaSkiaJre {
/**
* The native libraries needed to run alphaSkia.
* The alphaSkia initializer for Linux.
*/
public static final String[] libraries = {
"/native/linux-" + getCurrentArchitecture() + "/libalphaskiajni.so"
};
public static final AlphaSkiaLinux INSTANCE = new AlphaSkiaLinux();

private AlphaSkiaLinux() {
}

private static String getCurrentArchitecture() {
var jarch = System.getProperty("os.arch");
return switch (jarch) {
case "x86", "i368", "i486", "i586", "i686" -> "x86";
case "x86_64", "amd64" -> "x64";
case "arm" -> "arm";
case "aarch64" -> "arm64";
default -> jarch;
@Override
protected String[] getJavaResources() {
return new String[] {
"/native/linux-" + getCurrentArchitecture() + "/libalphaskiajni.so"
};
}
}
Loading

0 comments on commit 34b2495

Please sign in to comment.