在Android中使用Jena本体API遇MavenLocal()方法找不到错误求助
Hey there, let's work through your issues one by one:
1. Immediate Fix: Gradle DSL Method Name Case Sensitivity
The error you're seeing is because Gradle uses case-sensitive method names for repository configurations. You wrote MavenLocal() (capital M) but the correct method is mavenLocal() (lowercase m).
Here's the corrected allprojects block:
allprojects { repositories { google() jcenter() mavenLocal() // Note the lowercase 'm' } }
2. Verify Jena Module Placement & Local Repository Setup
Your current placement of Jena modules in D:\myproject.gradle won't be picked up by mavenLocal() by default, because mavenLocal() points to your user-specific Maven repository (usually C:\Users\<YourUsername>\.m2\repository on Windows). You have two reliable options here:
Option A: Install Jena Modules to Local Maven Repository
If you have Maven installed locally, navigate to the directory containing your Jena .jar files or POM files, and run this command (replace <path-to-jena-android-arq.jar> with the actual file path):
mvn install:install-file -Dfile=<path-to-jena-android-arq.jar> -DgroupId=mobi.seus.jena -DartifactId=jena-android-arq -Dversion=2.13.0 -Dpackaging=jar
Repeat this for any other Jena modules you need. This will add the files to your .m2 repository, and mavenLocal() will find them automatically.
Option B: Add a Flat Directory Repository
If you prefer to keep the modules in D:\myproject.gradle, add a flatDir repository to your repositories block (you can keep mavenLocal() too if needed):
allprojects { repositories { google() jcenter() mavenLocal() flatDir { dirs 'D:\\myproject.gradle' // Use double backslashes for Windows file paths } } }
Note: If you use this option, ensure your Jena modules include proper POM files so Gradle can resolve the dependency correctly—Option A is generally more stable for Maven-style dependency declarations.
3. Complete Your Packaging Options Configuration
Your provided packagingOptions block appears cut off. Make sure it's properly closed within the android block:
android { // ... other Android configs (minSdkVersion, compileSdkVersion, etc.) packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' } }
Final Checks
- Confirm that Jena-Android version
2.13.0is compatible with your minSdkVersion 21 (it should work without issues, but it's good to verify). - After applying these changes, sync your Android project again—this should resolve the method-not-found error and help Gradle locate your Jena dependencies successfully.
内容的提问来源于stack exchange,提问作者Janice.C

