1

I have a service project that I build and added the jar into my other projects libs folder.

I have added the jar gradle.build

flatDir { dirs 'libs' }
compile('com.proj:service-client:0.0.1-SNAPSHOT')

The jar added to class path and visible in Project and External dependencies folder

But still I cannot build the app and Eclipse also showing cannot be resolved to a type errors for the classes I have in external jar. Externel jar is build with gradle(gradlew build)

user09
  • 920
  • 2
  • 12
  • 38
  • Have you personally looked in this jar and made sure the class file is actually where it is supposed to be? – nitind Jun 05 '18 at 20:03
  • @nitind Yes I have extracted the jar and can see all the classes with right package names. I tried refresh,rebuild many time in eclipse. – user09 Jun 05 '18 at 20:07
  • Didn't forget an import did you? XD – Zannith Jun 05 '18 at 20:13
  • what happens when you build it through gradle? If it builds, sometime, deleting the project without deleting from actual disc and re-importing fixes this kind of issue. – cosmos Jun 05 '18 at 20:14
  • @Zannith It is not showing import aswell. It cannot resolve import. So both imports and classes have errors. Is it Ok to create jar with gradle and use it is as external jar? (P.S: I have installed the jar and used mavenLocal() to import it, it works fine but I can't push the app to cloud as the jar oly available in maven local repo) – user09 Jun 05 '18 at 20:17
  • @cosmos gradle build failed on second project with cannot resolve errors. I tried removing and importing project but that doesn't help – user09 Jun 05 '18 at 20:19
  • @arjun see my answer below. – cosmos Jun 05 '18 at 20:20
  • Sometimes with eclipse it helps to project clean, exit, turn off your computer, buy a new motherboard, and rewire your house, then everything usually works for me – Zannith Jun 05 '18 at 20:30
  • Is the layout of the jar correct with the root of its package layout being in the root of the jar? – nitind Jun 05 '18 at 22:40
  • Do one thing in the last tab of the project's Properties and order and export try to put your external jar on top. – Zia Jun 06 '18 at 05:13
  • Luck is with me this morning. This time I did a gradle install instead of gradle build and copied that jar and put it in the libs folder. See what errors gone – user09 Jun 06 '18 at 12:16

1 Answers1

0

Put the jar in some resource folder say src/main/resources/lib. In your build.gradle add following:

dependencies {
.
.
.
    compile files('src/main/resources/lib/vadr-aps-client-0.0.1-SNAPSHOT.jar')
.
.
}
cosmos
  • 2,143
  • 2
  • 17
  • 27
  • Still has the same problem. I can see jar's path is updated in build path that it got from resource/lib folder. I tried all the ways in this link https://stackoverflow.com/questions/20700053/how-to-add-local-jar-file-dependency-to-build-gradle-file – user09 Jun 05 '18 at 20:23
  • Just to make sure, did you provide exact name of the jar? Not name:version pattern? – cosmos Jun 05 '18 at 20:25
  • Don't forget to `right click project -> gradle -> Refresh Gradle Project` before you build in eclipse. – cosmos Jun 05 '18 at 20:26
  • My last advice would be delete all, eclipse and gradle related files that are `generated` during import and build from workspace and import it again. – cosmos Jun 05 '18 at 20:29
  • I deleted every project from eclipse, removed eclipse settings file from project, removed .gradle folder to remove entire repo and imported projects into eclipse and did a gradle refresh. Still those errors didn't go away – user09 Jun 05 '18 at 21:01