Venho tentando resolver esse erro a alguns dias, cheguei a encontrar em um fórum onde uma pessoa informava: “You need install all Library jasperreports”, eu sou meio leigo nisso eu imagino que já tenho instalado, instalei com base na propria wiki do Stella Boleto
Meu build.gradle:
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'com.google.android.libraries.places:places:2.5.0'
implementation 'com.google.firebase:firebase-database:20.0.2'
implementation 'com.google.firebase:firebase-analytics'
implementation files('libs/mail.jar')
implementation files('libs/activation.jar')
implementation files('libs/additionnal.jar')
implementation files('libs/caelum-stella-boleto-2.1.5.jar')
implementation files('libs/caelum-stella-core-2.1.5.jar')
implementation files('libs/barbecue-1.5-beta1.jar')
implementation files('libs/jasperreports-6.18.1.jar')
implementation files('libs/itextpdf-5.5.13.2.jar')
implementation files('libs/commons-beanutils-1.9.4.jar')
implementation files('libs/commons-collections4-4.4.jar')
implementation files('libs/commons-digester3-3.2.jar')
implementation files('libs/commons-logging-1.2.jar')
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'com.google.firebase:firebase-storage:20.0.0'
testImplementation 'junit:junit:4.13.2'
implementation platform('com.google.firebase:firebase-bom:28.3.1')
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Tive que adicionar um resources.excludes porque retornava erro de duplicancia
android {
packagingOptions {
resources.excludes.add('jasperreports_extension.properties');
}
}
implementei os mais atualizado mas desconfio que vá ocorrer erro no itext futuramente, eu peguei o mais atualizado que achei no Maven Repository não sei se é o certo, textei varios mais o erro continuava.
Essa é a parte do codigo onde ocorre o erro.
GeradorDeBoleto gerador = new GeradorDeBoleto(boleto);
// gerador.geraPDF é onde ocorre o erro
gerador.geraPDF(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/BoletoBradesco.pdf");
// Aqui também da erro se eu remover a o de cima
gerador.geraPDF(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/BoletoBradesco.png");
// Para gerar um array de bytes a partir de um PDF
@SuppressWarnings("unused")
byte[] bPDF = gerador.geraPDF();
// Para gerar um array de bytes a partir de um PNG
@SuppressWarnings("unused")
byte[] bPNG = gerador.geraPNG();
Por via de curiosidade esse é o erro completo que me retorna.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.imovel.find_imovel, PID: 13648
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Font;
at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.resolveObject(ContextClassLoaderObjectInputStream.java:121)
at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1401)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2002)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:503)
at net.sf.jasperreports.engine.base.JRBaseReport.readObject(JRBaseReport.java:777)
at java.lang.reflect.Method.invoke(Native Method)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1067)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1902)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1803)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:278)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:262)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:737)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:1061)
at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraRelatorio(GeradorDeBoleto.java:119)
at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraPDF(GeradorDeBoleto.java:160)
at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraPDF(GeradorDeBoleto.java:210)
at com.imovel.find_imovel.Login$2.onClick(Login.java:280)
at android.view.View.performClick(View.java:7339)
at android.widget.TextView.performClick(TextView.java:14275)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View.performClickInternal(View.java:7305)
at android.view.View.access$3200(View.java:846)
at android.view.View$PerformClick.run(View.java:27787)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7078)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.Font" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.imovel.find_imovel-AWR9m2pBsYlrNtHAdi7qZQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.imovel.find_imovel-AWR9m2pBsYlrNtHAdi7qZQ==/lib/arm64, /system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.resolveObject(ContextClassLoaderObjectInputStream.java:121)
at java.io.ObjectInputStream.checkResolve(ObjectInputStream.java:1401)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2002)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:503)
at net.sf.jasperreports.engine.base.JRBaseReport.readObject(JRBaseReport.java:777)
at java.lang.reflect.Method.invoke(Native Method)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1067)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1902)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1803)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:278)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:262)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:737)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:1061)
at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraRelatorio(GeradorDeBoleto.java:119)
at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraPDF(GeradorDeBoleto.java:160)
at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraPDF(GeradorDeBoleto.java:210)
at com.imovel.find_imovel.Login$2.onClick(Login.java:280)
at android.view.View.performClick(View.java:7339)
at android.widget.TextView.performClick(TextView.java:14275)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View.performClickInternal(View.java:7305)
at android.view.View.access$3200(View.java:846)
at android.view.View$PerformClick.run(View.java:27787)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7078)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)