Secured Android SharedPreferences Error: 'Caused by: java.lang.RuntimeException: Field keySize_ for...' - security

In an Android Kotlin project, I implemented EncryptedSharedPreference feature based on this link using the androidx.security library and it worked well in debug mode. But in release mode, I keep getting this error
java.lang.ExceptionInInitializerError
at com.package_name.i.a.f(:46)
at com.package_name.i.a.j(:52)
at com.package_name.i.a.e(:82)
at com.package_name.MyApplication.onCreate(:37)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Field keySize_ for k.a.d.a.h0.u not found. Known fields are [private int k.a.d.a.h0.u.i, private static final k.a.d.a.h0.u k.a.d.a.h0.u.j, private static volatile k.a.d.a.i0.a.a1 k.a.d.a.h0.u.k]
at k.a.d.a.i0.a.v0.n0(:608)
Please kindly share your ideas on how to solve this error.

This bug is related to Minify Enabled, which most likely causes some values to be removed.
A bug is reported already, you can track it here:
https://issuetracker.google.com/issues/157983099

-keep class com.google.crypto.** { *; }

Something is wrong with the rc2 version of android crypto of may 20. So it is better to use 1.0.0-alpha02 in your gradle file.
Remember, takes care with dependencies which are not in rc. You can also fix the issue with a proguard rules (see comment of Sebas LG).
dependencies {
implementation "androidx.security:security-crypto:1.0.0-alpha02"
}
Official documentation : https://developer.android.com/jetpack/androidx/releases/security
Linked commits : https://android.googlesource.com/platform/frameworks/support/+log/f66cdf1658639bd74ae850dfe3c1f5bb72eaebe6..6be101c2241593fee3ef9ab4e1fb337b485f2f9a/security/crypto

I solved using
dependencies {
..
implementation "androidx.security:security-crypto:1.0.0-rc03"

This is due to the fact that AndroidX security library uses the Google Tink library(This is already fixed in Tink 1.4.0), where there is a flaw in working with Proguard.
Add this code to proguard-rules.pro and this should help:
-keepclassmembers class * extends com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite {
<fields>;
}
Links:
https://github.com/google/tink/issues/361
https://github.com/google/tink/blob/master/java_src/src/main/resources/META-INF/proguard/protobuf.pro

Related

Optaplanner multithreading attempt yielded "missing rebase" on custom move

I updated from 7.5 to 7.9 Optaplanner libraries for use with a variant of the nurserostering code, and used the release notes (for example, some method names changed) to successfully rebuild and re-run. Then, I added the "moveThreadCount" xml line (for multithreading) to my solver config xml.
<moveThreadCount>AUTO</moveThreadCount>
Running then immediately threw an error:
Caused by: java.lang.UnsupportedOperationException: The custom move class (class westgranite.staffrostering.solver.move.EmployeeChangeMove) doesn't implement the rebase() method, so multithreaded solving is impossible.
I do have a number of custom moves. I did not see any reference to the need to add a rebase() method in the release notes, nor do I see a reference to rebase() in the current (newer) documentation section on building custom moves.
https://docs.optaplanner.org/7.12.0.Final/optaplanner-docs/html_single/index.html#customMoves
Would someone please point me the right way? Thanks!
I would suggest reading this excellent blog post: http://www.optaplanner.org/blog/2018/07/03/AGiantLeapForwardWithMultithreadedIncrementalSolving.html as it gives a more in depth explanation of how multithreaded solving works.
I also suggest to read the javadoc on the rebase method, it should point you in the right direction: https://docs.optaplanner.org/7.12.0.Final/optaplanner-javadoc/org/optaplanner/core/impl/heuristic/move/Move.html#rebase-org.optaplanner.core.impl.score.director.ScoreDirector-
Here's an example:
public class CloudComputerChangeMove extends AbstractMove<CloudBalance> {
private CloudProcess cloudProcess;
private CloudComputer toCloudComputer;
...
#Override
public CloudComputerChangeMove rebase(ScoreDirector<CloudBalance> destinationScoreDirector) {
return new CloudComputerChangeMove(
destinationScoreDirector.lookUpWorkingObject(cloudProcess),
destinationScoreDirector.lookUpWorkingObject(toCloudComputer));
}
}

java.lang.NoSuchMethodError - okhttp3 (Android)

My app keeps crashing. Can't figure out where the issue is. I'm not even using okttp3 library.
Currently, I'm only using retrofit 1.9 and otto 1.3.8
java.lang.NoSuchMethodError: No virtual method callEnqueue(Lokhttp3/Call;Lokhttp3/Callback;Z)V in class Lokhttp3/internal/Internal; or its super classes (declaration of 'okhttp3.internal.Internal' appears in /data/app/com.myproj.sample-2/base.apk)
at okhttp3.ws.WebSocketCall.enqueue(WebSocketCall.java:108)
at io.socket.engineio.client.transports.WebSocket.doOpen(WebSocket.java:73)
at io.socket.engineio.client.Transport$1.run(Transport.java:75)
at io.socket.thread.EventThread.exec(EventThread.java:50)
at io.socket.engineio.client.Transport.open(Transport.java:70)
at io.socket.engineio.client.Socket.probe(Socket.java:458)
at io.socket.engineio.client.Socket.onOpen(Socket.java:471)
at io.socket.engineio.client.Socket.onHandshake(Socket.java:512)
at io.socket.engineio.client.Socket.onPacket(Socket.java:485)
at io.socket.engineio.client.Socket.access$900(Socket.java:30)
at io.socket.engineio.client.Socket$5.call(Socket.java:299)
at io.socket.emitter.Emitter.emit(Emitter.java:117)
at io.socket.engineio.client.Transport.onPacket(Transport.java:127)
at io.socket.engineio.client.transports.Polling$2.call(Polling.java:124)
at io.socket.engineio.parser.Parser.decodePayload(Parser.java:251)
at io.socket.engineio.client.transports.Polling._onData(Polling.java:134)
at io.socket.engineio.client.transports.Polling.onData(Polling.java:106)
at io.socket.engineio.client.transports.PollingXHR$5$1.run(PollingXHR.java:113)
at io.socket.thread.EventThread$2.run(EventThread.java:75)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Solved it with the help of this post.
Just add the following to your gradle dependecies.
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okhttp3:okhttp-ws:3.4.1'
Try these dependencies :
implementation 'com.shopify.mobilebuysdk:buy3:3.2.3'
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
Hope this may help you.

Error with Nullable annotation when generating Javadoc using doclava

I am trying to generate a Javadoc for an Android Library using Doclava in Android Studio. The source code uses "Nullable" tag at some point and this causes a crash while generating the javadoc:
In doclet class com.google.doclava.Doclava, method start has thrown an exception java.lang.reflect.InvocationTargetException
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for javax.annotation.Nullable not found
Can I somehow overcome this?
I had to include in Javadoc's classpath, the findbugs:jsr305 library.
So, in my Gradle configuration, I added:
dependencies {
// For Doclava JavaDoc
jaxDoclet("com.google.doclava:doclava:1.0.6")
classpaths files('build/intermediates/classes/release')
classpaths 'com.google.code.findbugs:jsr305:3.0.1'
}
task javadoc(type: Javadoc) {
//.... the rest of the configuration
options {
classpath += configurations.classpaths.files.asType(List)
//.... the rest of the configuration
}
}
For this exception, check here: https://code.google.com/p/android/issues/detail?id=1261
Just add -XDignore.symbol.file to the end of the command, and it may remove this exception.

java.lang.VerifyError: me.xxx.menu.MenuListFragment only on Android 2.x.x

after almost 2 week trying to solve this strange problem, I give up!
Basically a get the java.lang.VerifyError every time I try to run my app
only in devices with Android 2.x.x. From 3.x.x all are going well.
In the project I'm using this two external library:
Action Bar Sherlock - http://actionbarsherlock.com/ - updated at the v4.4.0
Sliding Menu - https://github.com/jfeinstein10/SlidingMenu
This is what the LogCat return every time:
FATAL EXCEPTION: main
java.lang.VerifyError: me.xxx.menu.MenuListFragment
at me.xxx.menu.BaseSlidingMenuActivity.onCreate(BaseSlidingMenuActivity.java:46)
at me.xxx.menu.SlidingMenuCustomAnimation.onCreate(SlidingMenuCustomAnimation.java:28)
at me.xxx.XXXActivity.onCreate(XXXActivity.java:130)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
and this is how the BaseSlidingMenuActivity.java looks like around the line 46:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mTitleRes);
// set the Behind View
setBehindContentView(R.layout.frame_content);
if (savedInstanceState == null) {
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new MenuListFragment(); <--- ERROR HERE!
t.replace(R.id.frame_content, mFrag);
t.commit();
} else {
mFrag =(SherlockListFragment)this.getSupportFragmentManager()
.findFragmentById(R.id.frame_content);
}
...
...
}
Where MenuListFragment() is a SlidingFragmentActivity that extend a SherlockFragmentActivity
and implements SlidingActivityBase.
Of course I googled the problem, and seems that a lot of people are getting this
issue with the last version of the Android SDK tool, i.e. v22.x.x , in fact a have
the v22.6.3.
Some people resolved the VerifyError just putting the Check on the "Private Libraries"
box, inside "BuildPath->Configure BuildPath->Order and Export" menù, as explained
in other conversation about the VerifyError, but for me doesn't work, even because the "Private Libraries" was already checked. So the libraries/imports situation seems to be ok!
Hoping that someone already fund a solution for that! I'm getting crazy! :D
Thank you!
I finally found the solution!
Recap! Basically the are two main reason in which you can get this error:
(In my case) I was getting the VerifyError all the time that I tried to run my app on devices with API Level under 10 , because I was trying to catch an SQLiteDatabaseLockedException that are supported from the Android API Level 11. So to solve it check that every Exception or possible method (i.e. String.isEmpty() is supported from API Level 9) is supported form your minimum API Level.
While I was searching for a solution I found a lot of people that got the VerifyError because there was some problem with Libraries Imports, as explained in this post: http://commonsware.com/blog/2013/05/23/do-not-manually-modify-eclipse-build-path-except-now-r22.html
Hope that will help someone beyond me! :D
Bye Bye! Caterpillar.

WebSphereApplication NoClassDefFoundError while unmarshalling XML with JAXB

I´ve deployed an EAR on a Websphere Application Server 7. In my code there is a part where I try to unmarshall a XML file into an object. I get this error when trying to do that:
java.lang.NoClassDefFoundError: com.ibm.xtq.bcel.util.SyntheticRepository (initialization failure)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:140)
at com.ibm.xtq.bcel.classfile.JavaClass.<init>(JavaClass.java:109)
at com.ibm.xtq.bcel.classfile.JavaClass.<init>(JavaClass.java:228)
at com.ibm.xtq.bcel.generic.ClassGen.getJavaClass(ClassGen.java:174)
at com.ibm.fcg.bcel.FcgClassGenBCEL.dump2(Unknown Source)
at com.ibm.fcg.bcel.FcgClassGenBCEL.dump(Unknown Source)
at com.ibm.xml.xlxp2.jaxb.unmarshal.codegen.fcg.FCGDeserializationStubGenerator.generate(FCGDeserializationStubGenerator.java:249)
at com.ibm.xml.xlxp2.jaxb.codegen.AbstractGeneratedStubFactory.generateByteCode(AbstractGeneratedStubFactory.java:96)
at com.ibm.xml.xlxp2.jaxb.unmarshal.codegen.fcg.FCGStubFactory.generateStubByteCode(FCGStubFactory.java:46)
at com.ibm.xml.xlxp2.jaxb.codegen.AbstractGeneratedStubFactory.getStubClassConstructor(AbstractGeneratedStubFactory.java:154)
at com.ibm.xml.xlxp2.jaxb.unmarshal.codegen.AbstractGeneratedDeserializationStubFactory.createStub(AbstractGeneratedDeserializationStubFactory.java:58)
at com.ibm.xml.xlxp2.jaxb.unmarshal.impl.DeserializationContext.startComplexType(DeserializationContext.java:662)
at com.ibm.xml.xlxp2.jaxb.unmarshal.impl.DeserializationContext.handleRootElementEvent(DeserializationContext.java:303)
at com.ibm.xml.xlxp2.jaxb.unmarshal.impl.JAXBDocumentScanner.produceRootElementEvent(JAXBDocumentScanner.java:186)
at com.ibm.xml.xlxp2.scan.DocumentScanner.scanRootElement(DocumentScanner.java:2234)
at com.ibm.xml.xlxp2.scan.DocumentScanner.scanProlog(DocumentScanner.java:1726)
at com.ibm.xml.xlxp2.scan.DocumentScanner.nextEvent(DocumentScanner.java:1316)
at com.ibm.xml.xlxp2.scan.DocumentScanner.parseDocumentEntity(DocumentScanner.java:1168)
at com.ibm.xml.xlxp2.jaxb.unmarshal.impl.JAXBDocumentScanner.unmarshal(JAXBDocumentScanner.java:125)
at com.ibm.xml.xlxp2.jaxb.unmarshal.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:120)
at com.inditex.lois.core.ws.utilidades.services.impl.AdaptadorServiceImpl.transformarXMLenObjeto(AdaptadorServiceImpl.java:137)
As far as I know that class is part of IBM JDK and cannot be found in runtime. Is there anything I have to modify in my ear or, as I guess, its all about configuring/modifiying WAS configuration (or even applying a patch if this is a bug).
Any help? Thanks a lot.
(Sorry for my english :) )
This exception means that the class com.ibm.xtq.bcel.util.SyntheticRepository is found, but failed static initialization. If there is no other message in the log about this, then this is the time to open a PMR with IBM. Static initializers in internal WebSphere code should never fail during normal usage course.
Same here, there is an APAR:
http://www-01.ibm.com/support/docview.wss?uid=swg1IV41639
Problem conclusion
This defect will be fixed in:
6.0.0 SR14
6.0.1 SR6
7.0.0 SR5
.
The fix resolved the AccessControlException. SyntheticRepository
class can be initialized properly, hence NoClassDefFoundError
does not occur.

Resources