andrefigas / RustJNI

Apache License 2.0
49 stars 3 forks source link

Can't run sample code in Android Studio #9

Open Megadash452 opened 2 weeks ago

Megadash452 commented 2 weeks ago

Opening the directories sample/kotlin or sample/java with Android Studio will show an error saying that the plugin (and plugin test) was not found, even after running ./gradlew publishToMavenLocal on both gradle-plugin and gradle-plugin-test.

Here is the error:

A problem occurred configuring project ':app'.
> Could not resolve all artifacts for configuration ':app:classpath'.
   > Could not resolve io.github.andrefigas.rustjni:RustJNI:0.0.17.
     Required by:
         project :app > io.github.andrefigas.rustjni:io.github.andrefigas.rustjni.gradle.plugin:0.0.17
      > No matching variant of io.github.andrefigas.rustjni:RustJNI:0.0.17 was found. The consumer was configured to find a library for use during runtime, compatible with Java 17, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.7' but:
          - Variant 'apiElements' declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 21 and the consumer needed a component for use during runtime, compatible with Java 17
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
          - Variant 'javadocElements' declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about its target Java version (required compatibility with Java 17)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
          - Variant 'runtimeElements' declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component, compatible with Java 21 and the consumer needed a component, compatible with Java 17
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
          - Variant 'sourcesElements' declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about its target Java version (required compatibility with Java 17)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
   > Could not resolve io.github.andrefigas.rustjni-test:RustJNI:0.0.1.
     Required by:
         project :app > io.github.andrefigas.rustjni-test:io.github.andrefigas.rustjni-test.gradle.plugin:0.0.1
      > No matching variant of io.github.andrefigas.rustjni-test:RustJNI:0.0.1 was found. The consumer was configured to find a library for use during runtime, compatible with Java 17, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.7' but:
          - Variant 'apiElements' declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 21 and the consumer needed a component for use during runtime, compatible with Java 17
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
          - Variant 'javadocElements' declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about its target Java version (required compatibility with Java 17)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
          - Variant 'runtimeElements' declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component, compatible with Java 21 and the consumer needed a component, compatible with Java 17
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
          - Variant 'sourcesElements' declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about its target Java version (required compatibility with Java 17)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')

Building the sample projects with ./gradlew app:rust-jni-compile-test works, so this must be something with the IDE, maybe we need to add some configuration for it to work?

andrefigas commented 1 day ago

Closed by https://github.com/andrefigas/RustJNI/pull/12

Megadash452 commented 1 day ago

Reopened this issue because the samples still don't work, but now for different reasons. I had to update the gradle versions used by the plugin and the samples, and now this code in gradle-plugin/build.gradle.kts does not work and shows this error: Unresolved reference: pluginBundle

pluginBundle {
    website = "https://github.com/andrefigas/RustJNI"
    vcsUrl = "https://github.com/andrefigas/RustJNI"
    description = "A Gradle plugin that simplifies the creation and compilation of Rust code integrated with Android applications via JNI."
    tags = listOf("rust", "jni", "android", "gradle-plugin", "native-code", "android-development", "rust-jni")
}

After removing this, I compile the plugin and it works. Then I try compiling the kotlin sample and got an error saying that it tried looking for the rust directory in ~/.gradle/<version>/app/src/main/rust I cleaned all the project folders and without changing anything i recompiled them and the issue was gone and I haven't been able to recreate it since.

I also notice that when the plugin generates the jni code for the kotlin/java class the libname is empty: System.loadLibrary("")

Megadash452 commented 1 day ago

Well I got the error again when compiling the kotlin sample

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:rust-jni-compile'.
> Could not find 'rust_jni.rs' file at /home/marti/.gradle/daemon/8.9/./app/src/main/rust/src/rust_jni.rs
Megadash452 commented 1 day ago

I was able to solve all these issues but I haven't been able to push all the changes and still need to check the tests