Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Android libraries e.g. androidx.documentfile or com.android.support:support-v4 or com.android.support:support-v4? #415

Closed
ctoabidmaqbool opened this issue Dec 20, 2024 · 2 comments

Comments

@ctoabidmaqbool
Copy link

I am creating custom Attach plugin, but I am not sure how to use Android native libraris while developming the plugins native coding e.g. DalvikPdfViewerService.java.

I am trying to create custom Attach plugin e.g. pdfViewer.

I have added the lib depedency in modules/pdfviewer/build.gradle e.g.

implementation 'com.android.support:support-v4:28.0.0'

but still i can't use imports form this library e.g. import android.support.v4.provider.DocumentFile;

show how can i use native libs e.g. containing .aar files.

in previous javafxmobile-plugin i can simply use

project.afterEvaluate {
    explodeAarDependencies(project.configurations.androidCompile)
    explodeAarDependencies(project.configurations.compile)
}

now how can i use while creating attach plugin or in project which is using attach plugins.

@ctoabidmaqbool
Copy link
Author

I think, only way to copy and past lib's codding directly, which is still not better way to doing things.
like xzing lib is directly copy & past without importing xzing lib.

https://github.com/gluonhq/attach/tree/master/modules/barcode-scan/src/main/native/android/dalvik/zxing

@ctoabidmaqbool
Copy link
Author

I’ve identified a solution based on the implementation in the attach plugins, specifically:

Here’s what worked for me:

Steps to Resolve:

1️⃣ Update the necessary files under the dalvik directory:
src/main/resources/META-INF/substrate/dalvik:

  • build.gradle: Defines Android-specific configurations.
  • android-dependencies.txt: Specifies required dependencies for the Android project.

Updated Files:

build.gradle:

apply plugin: 'com.android.library'

android {
    namespace 'com.gluonhq.helloandroid'
    compileSdkVersion 34

    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 34
    }

    buildFeatures {
        buildConfig = false
        resValues = false
    }
}

repositories {
    google()
}

dependencies {
    compileOnly fileTree(dir: '../libs', include: '*.jar')
    implementation 'androidx.documentfile:documentfile:1.0.1'
}

android-dependencies.txt:

implementation 'androidx.documentfile:documentfile:1.0.1'

2️⃣ Execute the build commands:

./gradlew -i :pdfviewer:nativeBuild
./gradlew :pdfviewer:publishToMavenLocal

This process ensures that all required files, such as android-dependencies.txt, AndroidManifest.xml, and build.gradle, are properly copied and configured in the Android project directory.

Directory Structure After Build:

The resulting aar directory can be opened in Android Studio or IntelliJ IDEA for further development:

.
└── aar
    ├── build.gradle
    ├── gradle
    │   └── wrapper
    │       ├── gradle-wrapper.jar
    │       └── gradle-wrapper.properties
    ├── library
    │   ├── build.gradle
    │   └── src
    │       └── main
    │           ├── AndroidManifest.xml
    │           └── java
    │               └── com
    │                   └── gluonhq
    │                       └── helloandroid
    │                           └── DalvikPdfViewerService.java
    ├── libs
    │   └── util_classes.jar
    ├── local.properties
    └── settings.gradle

This approach allows the project to be natively integrated and customized further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant