{"id":13529417,"url":"https://github.com/libgdx/gdx-jnigen","last_synced_at":"2025-04-05T13:05:32.094Z","repository":{"id":44018427,"uuid":"189896652","full_name":"libgdx/gdx-jnigen","owner":"libgdx","description":"jnigen is a small library that can be used with or without libGDX which allows C/C++ code to be written inline with Java source code. ","archived":false,"fork":false,"pushed_at":"2025-03-18T09:37:33.000Z","size":1437,"stargazers_count":72,"open_issues_count":8,"forks_count":28,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-03-29T12:07:43.431Z","etag":null,"topics":["gradle","java","jni"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libgdx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-02T21:24:20.000Z","updated_at":"2025-03-18T09:37:38.000Z","dependencies_parsed_at":"2023-01-22T06:46:01.553Z","dependency_job_id":"64c84367-3671-43a4-880e-72eee6f69747","html_url":"https://github.com/libgdx/gdx-jnigen","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libgdx%2Fgdx-jnigen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libgdx%2Fgdx-jnigen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libgdx%2Fgdx-jnigen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libgdx%2Fgdx-jnigen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libgdx","download_url":"https://codeload.github.com/libgdx/gdx-jnigen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339155,"owners_count":20923014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gradle","java","jni"],"created_at":"2024-08-01T07:00:36.112Z","updated_at":"2025-04-05T13:05:32.065Z","avatar_url":"https://github.com/libgdx.png","language":"Java","funding_links":[],"categories":["Resources"],"sub_categories":["Others"],"readme":"## gdx-jnigen\n\n[![Build Status](https://github.com/libgdx/gdx-jnigen/workflows/Build%20and%20deploy/badge.svg)](https://github.com/libgdx/gdx-jnigen/actions?query=workflow%3A\"Build+and+deploy\")\n\nThe gdx-jnigen tool can be used with or without libGDX to allow C/C++ code to be written inline\nwith Java source code. \n\nThis increases the locality of code that conceptually belongs together (the Java native class methods and the actual implementation) and makes refactoring a lot easier\ncompared to the usual JNI workflow. Arrays and direct buffers are converted for you, further\nreducing boilerplate. Building the natives for Windows, Linux, macOS, and Android and iOS is handled for\nyou. jnigen also provides a mechanism for loading native libraries from a JAR at runtime, which\navoids \"java.library.path\" troubles.\n\nSee the libGDX Wiki for usage: https://libgdx.com/wiki/utils/jnigen\n\n\u003e [!CAUTION]\n\u003e The jnigen-runtime and jnigen-generator API is considered incubating and may change at any point.\n\n\u003e [!NOTE]\n\u003e For migrating from jnigen 2.x see the `MIGRATION.MD`\n\n\n## gdx-jnigen-gradle quickstart\n\nWe recommend you look at some existing projects for examples:\n- [gdx](https://github.com/libgdx/libgdx/blob/master/gdx/build.gradle) (Uses jnigen 2.x)\n- [gdx-freetype](https://github.com/libgdx/libgdx/blob/master/extensions/gdx-freetype/build.gradle) (Uses jnigen 2.x)\n- [gdx-bullet](https://github.com/libgdx/libgdx/blob/master/extensions/gdx-bullet/build.gradle) (Uses jnigen 2.x)\n- [gdx-video-desktop](https://github.com/libgdx/gdx-video/blob/master/gdx-video-desktop/build.gradle) (Uses jnigen 2.x)\n- [Jamepad](https://github.com/libgdx/Jamepad/blob/master/build.gradle) (Uses jnigen 2.x)\n- [gdx-box2d](https://github.com/libgdx/gdx-box2d/blob/master/build.gradle.kts) (Uses jnigen 3.x and kotlin DSL)\n\n\n## Configuring \n```gradle\n// Apply jnigen plugin\nplugins {\n    id \"com.badlogicgames.jnigen.jnigen-gradle\"\n}\n\n// ...\n\n// Define jnigen extension\njnigen {\n    // Your shared library name\n    sharedLibName = \"example\"\n    \n    //Enable multi threading compilation\n    multiThreadedCompile = true\n\n    // Shared configuration for all BuildTargets. Executed first\n    // See all BuildTarget options here: https://github.com/libgdx/gdx-jnigen/blob/master/gdx-jnigen/src/main/java/com/badlogic/gdx/jnigen/BuildTarget.java\n    // Most paths are relative to the $jniDir directory\n    // String options can be replaced by using `x = \"value\"` or appended to with `x += \"extravalue\"`\n    // String[] options can be replaced by using `x = [\"value\"]` or appended to with `x += \"extravalue\"` or `x += [\"extravalue\", \"extravalue2\"]`\n    all {\n        // Add extra flags passed to the C compiler\n        cFlags += [\"-fvisibility=hidden\"]\n        // Add extra flags passed to the C++ compiler\n        cppFlags += [\"-std=c++11\", \"-fvisibility=hidden\"]\n        // Add extra flags passed to the linker\n        linkerFlags += [\"-fvisibility=hidden\"]\n    }\n\n    // Configure robovm.xml for IOS builds, most simple libraries will not need to do this\n    robovm {\n        // Use preexisting robovm.xml, cannot be combined with other options.\n        //manualFile file(\"robovm.xml\")\n        \n        // Add extra patterns to forceLinkClasses\n        //forceLinkClasses \"test\", \"test2\"\n        //forceLinkClasses \"pattern3\"\n        // Add extra library \"test.a\" with variant \"device\"\n        //extraLib \"test.a\", \"device\"\n        //extraXCFramework \"libs/test.xcframework\"\n    }\n\n    // Add BuildTargets\n    // All BuildTarget options can be further customized in an OS+Arch specific manner within a {} block\n\n    // Add windows 32-bit BuildTarget and customize it\n    addWindows(x32, x86) {\n        //cFlags += [\"-fextraflag=fake\"]\n        //compilerPrefix = \"someprefix-\";\n        //cIncludes += \"windowsspecificdir/*.c\"\n    }\n    \n    //Add windows 64 bit, x86, MSVC toolchain \n    addWindows(x64, x86, MSVC) {\n        msvcPreLinkerFlags += [\"/MD\"]\n    }\n    \n    addWindows(x64, x86)    \n    addLinux(x32, x86)\n    addLinux(x64, x86)\n    addLinux(x32, ARM)\n    addLinux(x64, ARM)\n    addMac(x64, x86)\n    addMac(x64, ARM)\n    \n    //Auto add all possible ABIs \n    addAndroid() {\n        // Add extra content to the generated Application.mk file\n        //androidApplicationMk += [\"APP_STL := c++_static\"]\n    }\n    \n    //Add specific android ABI\n    addAndroid(AndroidABI.ABI_ARM64_V8A)\n    \n    //Auto add all possible iOS targets, including sim \n    addIOS() {\n        // Define ios framework bundle identifier\n        // xcframeworkBundleIdentifier = \"com.badlogic.gdx.JniGen\n        // Deinfe minimum supported iOS version\n        // minIOSVersion = \"11.0\"\n    }\n \n    \n    //Add specific ios device target\n    addIOS(x64, ARM, DEVICE)\n    \n    //Add ios 64 bit x86 simulator target\n    addIOS(x64, x86, SIMULATOR)\n\n\n    // Customize each BuildTarget that matches the condition\n    each({ it.os != Android \u0026\u0026 it.architecture != ARM }) {\n        //cppFlags += [\"-march=nocona\"]\n    }\n    // Customize everything again, can be used for conditional changes\n    each({ true }) {\n        //if(!it.cppCompiler.contains(\"clang\")) {\n        //    it.cFlags += [\"-flto\"]\n        //    it.cppFlags += [\"-flto\"]\n        //    it.linkerFlags += [\"-flto\"]\n        //}\n\n        //if(it.cppCompiler.contains(\"clang\"))\n        //    it.linkerFlags += [\"-Wl,-dead_strip\", \"-Wl,-s\"]\n        //else\n        //    it.linkerFlags += [\"-Wl,--gc-sections\"]\n    }\n}\n```\n\n## Building\n\nAfter the Gradle plugin is configured, jnigen will automatically generate and register\nappropriate tasks for building.\n\n### Generation\n`jnigen`\nRequired to be run before any other jnigen tasks, must be run any time source is changed\nor config is changed\n\ne.g. `./gradlew jnigen`\n\n### Compilation\n\n`jnigenBuildXXX`\nExecute the native compilation for the targets you want. Replace `XXX` with the target name.\n\ne.g. `./gradlew jnigenBuildAllWindows` Build all windows targets\n\ne.g. `./gradlew jnigenBuildLinuxArm_64` Build the 64-bit ARM Linux target only\n\n\n### Packaging\n`jnigenPackageXXX`\nPackage the native libraries into a jar. Replace `XXX` with the target name.\n\ne.g. `./gradlew jnigenPackageAll` Package all targets into their jars\n\ne.g. `./gradlew jnigenPackageAllIOS` Package the iOS targets into their jar\n\ne.g. `./gradlew jnigenPackageAllAndroid`    Package the Android targets into their jars\n\n\n### Publishing\n\nJnigen automatically generates publishing tasks that integrate with the maven publishing plugin.\nIf you are setup to publish to a maven repository, you can simply run:\n\n`./gradlew publish`\n\nYour artifacts will be published using `groupid:artifactid-platform:version:classifierXXX` as the coordinates.\n\nreplace classifierXXX with the target name.\n\ne.g. natives-desktop, natives-ios, natives-android-arm64-v8a \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibgdx%2Fgdx-jnigen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibgdx%2Fgdx-jnigen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibgdx%2Fgdx-jnigen/lists"}