I downloaded the Codename One tutorial project, added some custom code with libraries but when building the project I get 'Compliance Check Failed' error. This error is cauesed by multiple Proguard warnings like:
there were # unresolved references to library class members.
there were # unresolved references to program class members.
These libraries are working fine just the proguard warnings create an error. I want to add '-dontwarn' option to the proguard config file but the problem is there is no such file. Any ideas how to correct this error? I'm using IntelliJ Idea. Thanks for any help.
You can use the build hint android.proguardKeep to add the additional parameters e.g.:
android.proguardKeep=-keep class com.mypackage.ProblemClass { *; }`
You can add the build hints in Codename One Settings. See the developer guide for more.
Related
This question already has an answer here:
Eclipse Java IDE JUnit5: junit.jupiter.api.Assertions is not accessible
(1 answer)
Closed 2 years ago.
I am new to Java and Project Lombok, I am trying to follow some tutorials to understand it better. I have created a very simple java project to test the Project Lombok and it throws the error Data cannot be resolved to a type when I add the annotation #Data to my class.
I am using macOS and Eclipse IDE for running my Java application. Following are the steps that I followed to run my first Java and Lombok project:
Downloaded the latest Project Lombok version 1.18.16 and placed it in the Documents folder.
Installed the Project Lombok in my system using the command java -jar lombok.jar.
Restarted my Eclipse and verified that Project Lombok installed in the Eclipse -> About Eclipse: "Lombok v1.18.16 "Envious Ferret" is installed. https://projectlombok.org/"
Created a new Java project and the class Alien.
Added the Project Lombok JAR to my project Classpath.
Added the #Data annotation to my Alien class and imported the JAR file but I get the error The type lombok.Data is not accessible for my import statement import lombok.Data;
Also, I get the error Data cannot be resolved to a type for my annotation at the class level public #Data class Alien
I am really unsure what's wrong. I tried to find out but all the answers have mentioned the same steps. I was just wondering what am doing wrong. Any help would be really appreciated.
Following is my complete code:
package com.lamboktest;
import lombok.Data;
public #Data class Alien {
private int age;
private String name;
}
The error The type SOMETYPE is not accessible is... bizarre. As far as I know, there are only three ways to get that error:
lombok.Data isn't public. Except, it is, so this can't be it.
You've manually added a list of forbidden packages ('access rules') in eclipse, to deny yourself access to lombok. Presumably, you'd remember if you did that, so it can't be this.
lombok is loaded as a module, and the lombok package isn't exported. Except, the only versions of lombok that exist either aren't modularized (and module-info-less jar files export everything), or they are, and the lombok package is exported. So it can't be this.
Perhaps it would be useful to doublecheck all of these:
I guess javap -cp lombok.jar lombok.Data, and check that it's public, but, this just cannot be it, so you probably don't need to bother.
For that access rules thing, which is the most likely of 3 very unlikely options, go into your project's setup (right click on it in e.g. the package explorer, and pick 'properties...', you can set up lots of stuff from there), go to 'build path', find the lombok.jar, open it up, and check 'access rules'. It should read 'no rules defined'.
Go into your project's setup and ensure it's all set to java8, and rebuild. Presumably you want to use new features, but the point is to at least isolate down to: It's a module issue.
Posting the answer as it maybe useful for somebody in the future.
As mentioned in the comment removed/deleted the file module-info.java which was created by default during the project creation. Everything worked as expected.
I'm trying to include som Kotlin files in a rather large IntelliJ Java project, and I've stumbled upon a case where I get "unresolved reference" on absolutely every import.
The (simplified project structure:
Project:
saksbehandling
- e2e
- cucumber
- src
- test
- java
-e2e
- support
- common
- src
- main
- java
- common
- testdata
Kotlin classes in the support module work fine.
Kotlin classes in the common module does not.
The same file is located in the /e2e/cucumber/src/test/java/e2e/support and the /e2e/common/src/main/java/common/testdata folders. In the latter, I get "Unresolved reference" when I try any kind of import. Example:
import api.utils.ApiResourceFactory
import com.google.common.io.Resources
import e2e.utils.AdressIterator
Now, the api.utils an e2e.utils unresolved references are one thing. But the com.google reference? That tells me there's something seriously missing or broken.
I've been looking for conflicting versions etc., but it's all the same project, so how can the problem be related to that? Also, making the common module dependent on the cucumber module does not help, and also that's not a good idea.
Any ideas how to fix this probably silly newbie problem?
BTW: In addition, when creating the Kotlin file in the common module, where no imports work, suddenly a working Kotlin file in the cucumber module also starts getting Unresolved references on things that's been working until the new file was created.
UPDATE:
Using this link: https://www.baeldung.com/kotlin-maven-java-project to tweak the .pom file i was able to get most of the imports working.
However, some strange things are still not working:
import kotlin.collections.ArrayList still gives "Unresolved reference: ArrayLIst"
And in the code, I get "Unresolved reference" on the following
listOf()
educationMap[fnr] (the []'s - No set method providing array access
ComplaiuntWhoEnum::class.java.enumConstants - Unresolved reference: Java
I even get errors about Unresolve reference: Int (!)
UPDATE 2:
If I create a folder /common/src/main/kotlin, things look better. But then I'm unable to import those classes into classes in the cucumber module.
If your build fails outside of IntelliJ, you should probably start by fixing this. Maybe post the error you're getting and your build configuration to get help.
If everything works outside of IntelliJ IDEA, maybe the configuration of your modules is outdated and IntelliJ struggles to fix it.
2 solutions have worked so far for me when re-organizing modules in IntelliJ:
File > Invalidate caches / Restart
If the first one does not work, try removing the project, deleting IDEA files and re-importing
I am running Proguard via the Maven Plugin, you can see my configuration here: https://github.com/sanity/tahrir/blob/proguard-debug/pom.xml#L61
You can see the complete output of "mvn -DskipTests assembly:assembly" here: https://gist.github.com/ee1081179496e11916cb
Despite quite a bit of searching I cannot find any explanation of what causes this error, nor now I can fix it?
Your input contains a library class that depends on a program class. ProGuard warns about it and doesn't allow it, unless you specify -dontwarn. You should remove that option and check ProGuard's warnings for details.
See the ProGuard manual > Introduction
See the ProGuard manual > Troubleshooting > Warning: library class ... depends on program class ...
For me, having
proguard.config=proguard-project.txt
caused the same error.
Correcting to include both sdk and my config file like below fixed it.
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
When I try to export my apk with Proguard I get a lot of errors (over 400) similar to:
Warning: org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper: can't find superclass or interface javax.ws.rs.ext.ExceptionMapper
and
org.codehaus.jackson.xc.DataHandlerJsonDeserializer$1: can't find superclass or interface javax.activation.DataSource
I am using the Jackson Json library, and the errors seem related to that.
Researching this error I found the following from Proguards FAQ:
If there are unresolved references to classes or interfaces, you most likely forgot to specify an essential library. For proper processing, all libraries that are referenced by your code must be specified, including the Java run-time library. For specifying libraries, use the -libraryjars option.
Searching around on SO I found a lot of unanswered questions related to this, but the general sense was that the jar file I am using (in this case Jackon JSON) is relying on more libraries and they need to be added to Proguard's config file some how.
However, I can't figure out how to determine what jars are needed and where they are. The warnings mention a lot of different packages such as javax.ws.rs.ext, org.joda.time, org.codehaus.stax2, javax.xml.stream, etc.
How do I determine what jars contain those packages? For example, what jar is required for the javax.ws.rs.ext.** classes?
How do I figure out where those jars are and what path would be used with -libraryjars in Proguard?
Thanks much
Edit: I should also mention that I am using an Android Library Project setup. The jars are in the main Library project, and the actual working project has their build paths including the jars in the Library project. Don't know if that makes a difference but thought I should mention it.
Update Just to test, I completely removed the jackson far from the build path and from my code and now Proguard completes successfully. The questions still remain... What is the correct approach for handling these errors?
Does the Android export wizard in Eclipse automatically add the /lib/ jars to proguard or do they all have to be added manually in the proguard config file like this:
-libraryjars C:/Project/lib/somjar.jar
I did try that for the jackson one but it didn't make any difference. Does this mean I also have to find all of the jars that are needed for the classes mentioned in the warnings and add those? Would they be in the sdk or in the java installation?
Sorry if these are stupid questions, but I have been trying to figure this out for the last couple hours and have no idea what to do.
Thanks again
Update Again
So more searching, combined with Benjamin's suggestion, I found some of the missing classes were in rt.jar, which is in the jdk's lib folder. So I ended up adding
-libraryjars <java.home>/lib/rt.jar
To the proguard.cfg file and brought the warnings from 485 down to 204. Hey I guess that's something... The remaining warnings describe classes that I cannot find at all. The app works just fine without running proguard, so these classes must be somewhere right? Or are these warnings that I should use -dontwarn with?
The remaining classes are in these packages:
org.joda.time.
org.codehaus.stax2.
javax.ws.rs.
So now I just need a way to figure out:
What jars have these classes
Where are these jars so I can include them in the proguard config file
I've had similar problems with Proguard and similar errors I was using an osmdroid.jar which built OK unobfuscated. This jar must have had external dependencies which my application didn't need. Fortunately the authors listed the jars needed and once I downloaded them and told Proguard via the -libraryjars option, the Proguard build was OK.
Re your missing jars (which you probably don't really need, but Proguard thinks you might!), you should find them at:
org.joda.time
(The jar's inside the zip)
org.codehaus.stax2.
javax.ws.rs.
I only can provide an answer for the first part:
Give
http://www.findjar.com
a try, there you might find the names of the needed jar files
like so
You don't need to include the libraries for Proguard; you need to instead instruct Proguard to keep the class names and some other stuff. I toyed around with it a bit myself, and I ended up with something similar to this discussion:
-keepnames class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-dontwarn org.codehaus.jackson.**
If you're still experiencing crashes—and I would suggest testing vigorously!—you might want to keep Jackson completely intact with:
-keep class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-dontwarn org.codehaus.jackson.**
(Note that the latter produces a larger file.)
I'm getting an error message when I try to build my project in eclipse:
The type weblogic.utils.expressions.ExpressionMap cannot be resolved. It is indirectly referenced
from required .class files
I've looked online for a solution and cannot find one (except for those sites that make you pay for help). Anyone have any idea of a way to find out how to go about solving this problem? Any help is appreciated, thanks!
How are you adding your Weblogic classes to the classpath in Eclipse? Are you using WTP, and a server runtime? If so, is your server runtime associated with your project?
If you right click on your project and choose build path->configure build path and then choose the libraries tab. You should see the weblogic libraries associated here. If you do not you can click Add Library->Server Runtime. If the library is not there, then you first need to configure it. Windows->Preferences->Server->Installed runtimes
Add spring-tx jar file and it should settle it.
Have you Googled for "weblogic ExpressionMap"? Do you know what it is and what it does?
Looks like you definitely need to be compiling alongside Weblogic and with Weblogic's jars included in your Eclipse classpath, if you're not already.
If you're not already working with Weblogic, then you need to find out what in the world is referencing it. You might need to do some heavy-duty grepping on your jars, classfiles, and/or source files looking for which ones include the string "weblogic".
If I had to include something that was relying on this Weblogic class, but couldn't use Weblogic, I'd be tempted to try to reverse-engineer a compatible class. Create your own weblogic.utils.expressions.ExpressionMap class; see if everything compiles; use any resultant errors or warnings at compile-time or runtime to give you clues as to what methods and other members need to be in this class. Make stub methods that do nothing or return null if possible.
This issue happen because of few jars are getting references from other jar and reference jar is missing .
Example : Spring framework
Description Resource Path Location Type
The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.beans.factory.annotation.Autowire. Fix the build path then try building this project SpringBatch Unknown Java Problem
In this case "org.springframework.beans.factory.annotation.Autowire" is missing.
Spring-bean.jar is missing
Once you add dependency in your class path issue will resolve.
I was getting this error:
The type com.ibm.portal.state.exceptions.StateException cannot be resolved. It is indirectly referenced from required .class files
Doing the following fixed it for me:
Properties -> Java build path -> Libraries -> Server Library[wps.base.v61]unbound -> Websphere Portal v6.1 on WAS 7 -> Finish -> OK