RE: [LF71GA2] Unresolved requirement: Import-Package: com.google.zxing

Diego Cantone, modified 6 Years ago. Junior Member Posts: 42 Join Date: 11/10/16 Recent Posts
Hi, i'm having a hard time with gradle dependencies, here is the situation, in my build.gradle i have the following dependecies:     
compile group: 'com.google.zxing', name: 'core', version: '3.3.0'
compile group: 'com.google.zxing', name: 'javase', version: '3.3.0'

in my class i have the following imports without any errors: 
​​​​​​​import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

in project and external dependencies i have the following jars:
​​​​​​​javase-3.3.0.jar
core-3.3.0.jar

so, all seems to be ok, but when i deploy the module on the server i get this error:
​​​​​​​Unresolved requirement: Import-Package: com.google.zxing

As you can see in the screens attached, i really don't understand what's going wrong, can someone help me? 
Thanks
thumbnail
Olaf Kock, modified 6 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Diego Cantone
so, all seems to be ok, but when i deploy the module on the server i get this error:
​​​​​​​Unresolved requirement: Import-Package: com.google.zxing
At build-time, all requirements are met. The compiler knows the code that you're referring to.
At run-time, Liferay does not have access to all the code that was around at build time. Ideally the zxing jars would be OSGi bundles (please check), then you can just deploy them to Liferay. Otherwise you'll have to embed the code in your own modules.
Note that you might need some transitive dependencies as well. I don't have experience with the use of the zxing libraries.
Diego Cantone, modified 6 Years ago. Junior Member Posts: 42 Join Date: 11/10/16 Recent Posts
Olaf Kock
Diego Cantone
so, all seems to be ok, but when i deploy the module on the server i get this error:
​​​​​​​Unresolved requirement: Import-Package: com.google.zxing
At build-time, all requirements are met. The compiler knows the code that you're referring to.
At run-time, Liferay does not have access to all the code that was around at build time. Ideally the zxing jars would be OSGi bundles (please check), then you can just deploy them to Liferay. Otherwise you'll have to embed the code in your own modules.
Note that you might need some transitive dependencies as well. I don't have experience with the use of the zxing libraries.

Hi Olaf, thank for the answer, i've found the same library as an OSGI bundle, or i think so, correct me if i'm wrong, it should be this 
​​​​​​​compile group: 'org.apache.servicemix.bundles', name: 'org.apache.servicemix.bundles.zxing', version: '3.3.0_1' 
so as you said, and as is written in this tutorial , now it should work without problem..
But sadly i continue to get the same error.
thumbnail
Olaf Kock, modified 6 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Diego Cantone
But sadly i continue to get the same error.
Hi Diego,
it's not enough to change the compiler dependencies: That will only help you during build-time. At runtime, Liferay needs to have access to the libraries as well. Take the OSGi bundle(s) for this library and deploy it/them to Liferay, e.g. by dropping them into the deploy folder. Then you'll have them available at runtime as well, and the dependency issue should be resolved. (unless you're missing transitive dependencies)
Paolo Giannone, modified 6 Years ago. New Member Posts: 4 Join Date: 2/12/19 Recent Posts
Hi Diego,

try using:

compileInclude group: 'com.google.zxing', name: 'core', version: '3.3.0'
compileInclude group: 'com.google.zxing', name: 'javase', version: '3.3.0'​​​​​​

The 'compileInclude' configuration allows you to include the dependency in the compile classpath.
​​​​​​​Open your jar after the build: you will be able to find all the classes you need to run your code. 
Diego Cantone, modified 6 Years ago. Junior Member Posts: 42 Join Date: 11/10/16 Recent Posts
Thanks for the answers, i solved by editing the .bnd file with the include-resource tag and by including every jar needed with @core-3.3.0.jar,@javase-3.3.0.jar and so on.
thumbnail
Mahammad Ashik A, modified 6 Years ago. Junior Member Posts: 81 Join Date: 7/17/17 Recent Posts
Hi Diego Cantone,
I am facing same problem. How you resolved?
Could please share me your gradle and bnd file for reference.
​​​​​​​Thanks you