itextpdf - itextg Android lint error - android

I'm trying to use itextg but I'm getting some gradle errors. Any idea? I tried version 5.5.9 and 5.5.10.
Execution failed for task ':app:lint'.
Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
The first 3 errors (out of 482) were:
/Users/xxxxx/.gradle/caches/modules-2/files-2.1/com.itextpdf/itextg/5.5.10/247811bfc4d8f4e99c909236eadf4dfc6dfa1615/itextg-5.5.10.jar: Error: Invalid package reference in library; not included in Android: javax.xml.crypto.dom. Referenced from com.itextpdf.text.pdf.security.MakeXmlSignature. [InvalidPackage]
/Users/xxxxx/.gradle/caches/modules-2/files-2.1/com.itextpdf/itextg/5.5.10/247811bfc4d8f4e99c909236eadf4dfc6dfa1615/itextg-5.5.10.jar: Error: Invalid package reference in library; not included in Android: javax.xml.crypto.dsig.dom. Referenced from com.itextpdf.text.pdf.security.MakeXmlSignature. [InvalidPackage]
/Users/xxxxx/.gradle/caches/modules-2/files-2.1/com.itextpdf/itextg/5.5.10/247811bfc4d8f4e99c909236eadf4dfc6dfa1615/itextg-5.5.10.jar: Error: Invalid package reference in library; not included in Android: javax.xml.crypto.dsig.keyinfo. Referenced from com.itextpdf.text.pdf.security.MakeXmlSignature. [InvalidPackage]

As far I understood, Android doesn't contain the following packages.
javax.xml.crypto.dom
javax.xml.crypto.dsig
That's why itextpdf lib can't find references to them. To fix it, add the following dependency.
implementation group: 'javax.xml.crypto', name: 'jsr105-api', version: '1.0.1'

Sounds like transitive libraries missing. Try using { transitives = true} on that dependency and see if it helps. Also it looks like they might be using straight Java modules for security underneath the hood, so you may have to make sure you specify the right JAVA_VERSION to use in your build.gradle as well.
Also confirm that you can expand the project view, to the itextg area and see the following JARs have been pulled in.
itextpdf-x.y.z.jar
itext-xtra-x.y.z.jar
itext-pdfa-x.y.z.jar
xmlworker-x.y.z.jar
If you don't see them, then you may need to download them and include them manually. I'm not familiar with itext enough to know how they include their transitive dependencies, but they do call it out on GitHub that they are used in this, so confirm they are there.

Related

Multiple APKs packaging the same library can cause runtime errors with only one dynamic module on AGP 4.0.1?

I have only one dynamic feature module in my project called search, But when I try to build project, I get that Error:
[:search, :search] all package the same library [androidx.recyclerview:recyclerview].
Multiple APKs packaging the same library can cause runtime errors.
Placing each of the above libraries in its own dynamic feature and adding that
feature as a dependency of modules requiring it will resolve this issue.
Libraries that are always used together can be combined into a single feature
module to be imported by their dependents. If a library is required by all
feature modules it can be added to the base module instead.
Of Course, the first thing I did is to research about people who had the same problem And I found:
1- This Question
2- This medium article
Both Introduce the same solution (Use Android Gradle Plugin 4.0) and my project uses AGP 4.0.1, But the problem is that I have only one dynamic module called search. I don't have any other dynamic modules, even further I don't have the dependency of RecyclerView: androidx.recyclerview:recyclerview in my search gradle file, So this is maybe a transitive dependency.
Also, you can find that duplicated dependency in one of two ways:
1-Navigate to: PROJECT_NAME/module_name(In my case: search)/build/intermediates/
and then search for "deps.txt" file in that directory, Open the file and you will see all your module dependencies direct and transitive ones
2- run ./gradlew :module_name:dependencies task
If you tried to remove that duplicated line: androidx.recyclerview:recyclerview from "deps.txt" file, it gets generated again after each build.
That being said, I need some rule in my packagingOptions {} like exclude to prevent that conflict between search.aar and and any other search.* format
Can anyone help, please?
In my case, I removed the below from one of the modules
Note: not from the base module
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

kotlin-android-extensions stop working if lifecycle-extensions is included in gradle

After adding the Android lifecycle component to my project with the following line: implementation("androidx.lifecycle:lifecycle-extensions:$lifecycleVersion")
in my app's build.gradle.kts file all the import kotlinx.android.synthetic stop working, lifecycleVersion is defined as "2.0.0"
It gives me the following error in the places where I use the imported views. And the imports are marked as unused by the IDE
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
I tried moving the source code from the main/java folder to a main/kotlin one after searching for a solution online but it didn't work.
It seems like the issue was that since the navigation dependencies must be (for now) in the android.arch distribution adding androidx dependencies messed with the project.
The problem have been solved by replacing the previous conflicting dependency to:
implementation("android.arch.lifecycle:extensions:1.1.1")
It is curious that the only conflicting dependency was that one and not the others. But after changing all the dependencies to the android.arch distribution the problem have been solved.

Cannot access inherited library

In my android library I am using ceddl4j library but when I build my library and try to add it's aar file in another Application, it is throwing error
Error:(75, 44) error: cannot access DigitalData
class file for nl.mirabeau.ceddl4j.DigitalData not found
Adding ceddl4j into my library with
compile group: 'nl.mirabeau', name: 'ceddl4j', version: '1.0.0'
I am surely missing something in build configuration of my library, can someone please guide.
Thanks to Grabriele for providing the information that aar file does not contain the nested dependencies, hence the option left is maven repo (public or private).

Android - Invalid Package javax.servlet.MultipartConfigElement

My Android app has a Java library added via a Gradle dependency. When trying to perform ./gradlew build, I get the following error:
InvalidPackage: Package not included in Android
../../../../../../../../../.gradle/caches/modules-2/files-2.1/javax.servlet/javax.servlet-api/3.0.1/6bf0ebb7efd993e222fc1112377b5e92a13b38dd/javax.servlet-api-3.0.1.jar: Invalid package reference in library; not included in Android: javax.servlet.annotation. Referenced from javax.servlet.MultipartConfigElement.
I have control over the Java library so I can make changes. The error isn't really telling me where the reference to that is in my library and I can't seem to find an alternative for it.
Any ideas?
Update
I added the following to my Gradle:
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
But I still get the same error when doing ./gradlew build.
As per our discussion in comment . This error can be ignored by using the following code in gradle
lintOptions {
disable 'InvalidPackage'
}

Android Studio: Resolving Duplicate Classes

When I try to run my android application on an Android device, the gradle console reports the following error:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/loopj/android/http/AsyncHttpClient$1.class
When I search for the "AsyncHttpClient" class, I see that it's indeed being found in two separate locations:
/Users/Afflatus/.gradle/caches/modules-2/files-2.1/com.loopj.android/android-async-http/1.4.9/5d171c3cd5343e5997f974561abed21442273fd1/android-async-http-1.4.9-sources.jar!/com/loopj/android/http/AsyncHttpClient.java
/Users/Afflatus/.ideaLibSources/android-async-http-1.4.9-sources.jar!/com/loopj/android/http/AsyncHttpClient.java
The first path seems to suggest it's a "cache" file... so I've tried invalidating & restarting my cache, but both files are still there after the gradle gets rebuilt and I try to run the application. I've read in alternate posts that it can be resolved by deleting one of the files... So I went to the cache location and deleted all the files found in the "1.4.9" folder... unfortunantly after reopening Android Studio, a new cache file gets created and I get the same error.
Other posts (here, here,here, and here) suggest if I add "./gradlew clean" to the root directory it would rebuild the gradle again just for the run (as far as I understand). So I tried doing that as well:
Which made my app's folder look like this:
But unfortunantly, that didn't help things I still get the same error. What am I doing wrong? What should I be doing?
I added this line to my gradle.properties file and my app worked
android.enableJetifier=true
Sometimes duplicate classes exception means that one of your dependencies uses implicitly the older or newer (with +) version of some library you also use in your project,
To resolve this issue you may add such block of code (put your library version after 'force') to your build.gradle file (Module:app):
configurations {
all {
resolutionStrategy {
// do not upgrade above 3.12.0 to support API < 21 while server uses
// COMPATIBLE_TLS, or okhttp3 is used in project
force 'com.squareup.okhttp3:okhttp:3.12.0'
force 'com.squareup.okhttp3:logging-interceptor:3.12.0'
}
}
}
You may also exclude some group from your dependencies.
For a single dependency you way write:
dependencies {
// example
implementation('log4j:log4j:1.2.15') {
exclude group: 'javax.jms', module: 'jms'
}
}
Tested to work on Android Studio with Gradle Plugin version 3.4.2 and Gradle version 5.4.1.
Credits go to Dimitar Dimitrov and Schalk Cronjé from gradle org discussion group
That's because you have added some library two times in libs folder, this could happen sometimes when you have multiple versions of the same library in the libs folder. Check it and remove any duplicate jar files.
And the second option could be you have also added the dependency in gradle.build and also have a jar in libs folder.
So check both places and remove duplicate entries and then clean and build APK again.
Delete files with duplicate jar extensions in the libs folder. However, if there are no duplicate files and there is still a "Duplicate classes" error, look for the name in the rest of the "Duplicate classes ...." clause in the error section. For example, "duplicated classes 'dagger' bla bla". Delete the file named 'dagger' from the libs folder. (Be careful not to delete it with shift.)
In my case, I am using sensorocloud.jar and the compile 'com.loopj.android:android-async-http:1.4.9' in my gradle which caused the same error as yours. Because sensoro cloud SDK used loopj's async-http.
I managed to solve it by manually removing the duplicate .class files in the jar file. (i.e.
changing the extension from jar to zip
extract it
remove the com.loopj.android .class files)
(P.S. I have tried to search through the web to see if I could exclude certain class of a jar in gradle, but not succeed, e.g. I referenced this SO post)
This error can be caused by several things;
misconfigured package name
Activity views that is not well binded. - simply go to your launcher activity view and ensure context is defined well e.g "com.yourdomain.package"
Re-create your BuildConfig and set it up well.
Check if your project build.gradle. There it might be some maven duplicate dependency
Here's another situation that can cause duplicate class during the mergeDexClasses task. This can happen with later versions of android gradle.
If your build.gradle.kts script has a dependency in the form:
implementation(project(":mylib", configuration="default"))
that can cause duplicate classes. The correction is simple. Just change it to:
implemenation(project(:mylib"))
Here's the Android Studio's Team explanation:
Having both project(":lib") and project(path: ":lib", configuration: "default") in the runtime classpath means that AGP gets both build/classes/java/main and build/libs/lib.jar (run ./gradlew :lib:outgoingVariants --all to verify). Because paths differ, we'll get 2 dexing transforms happening: 1 incremental that produces dex per class under build/.transforms (the one processing dir) and another one which produces single dex (the one processing jar). Later on during merging this causes failure.
AGP never publishes to the default configuration, in fact java-library plugin does it only so it does not break older build scripts. Having an explicit configuration name used in the dependency declaration is discouraged and Gradle attributes should be used instead.
In an older version of AGP, I ran into a problem where adding the configuration value "default" fixed some issue I was having. Well that no longer works, and adding the "default" configuration you can get duplicate classes.

Categories

Resources