I've been trying to solve this exception that only happens in Android Lollipop (API 21). I tried to look for other solutions but the only one related is Generate KeyPair with KeyPairGeneratorSpec on API < 23 and the suggested solution didn't work.
Am I missing anything? Thanks!
Here's my code that's throwing at the last line:
Calendar start = Calendar.getInstance();
Calendar end = Calendar.getInstance();
end.add(Calendar.YEAR, 30);
KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(appContext)
.setAlias(getSecureSettingsKeyAlias())
.setSubject(new X500Principal("CN=" + getSecureSettingsKeyAlias()))
.setSerialNumber(BigInteger.TEN)
.setStartDate(start.getTime())
.setEndDate(end.getTime())
.build();
KeyPairGenerator kpg = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, AndroidKeyStore);
kpg.initialize(spec);
kpg.generateKeyPair();
Here's the exception that's happening:
Caused by: java.lang.IllegalStateException: Can't generate certificate
at android.security.AndroidKeyPairGenerator.generateKeyPair(AndroidKeyPairGenerator.java:136)
at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.getKeystore(FileSettingsStorage.java:302)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.writeSecureSettings(FileSettingsStorage.java:185)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSecureSettings(SettingsImpl.java:473)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSettings(SettingsImpl.java:321)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettingsToStorage(sampleIDService.java:102)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettings(sampleIDService.java:91)
at com.sampleid.sampleid.features.shared.BaseActivity.onStop(BaseActivity.java:182)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1261)
at android.app.Activity.performStop(Activity.java:6089)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3341)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3390)
at android.app.ActivityThread.access$1100(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.UnsupportedOperationException: private exponent cannot be extracted
at com.android.org.conscrypt.OpenSSLRSAPrivateKey.getPrivateExponent(OpenSSLRSAPrivateKey.java:161)
at org.spongycastle.jcajce.provider.asymmetric.rsa.RSAUtil.generatePrivateKeyParameter(RSAUtil.java:63)
at org.spongycastle.jcajce.provider.asymmetric.rsa.DigestSignatureSpi.engineInitSign(DigestSignatureSpi.java:95)
at java.security.Signature$SignatureImpl.engineInitSign(Signature.java:679)
at java.security.Signature.initSign(Signature.java:330)
at com.android.org.bouncycastle.x509.X509Util.calculateSignature(X509Util.java:243)
at com.android.org.bouncycastle.x509.X509V3CertificateGenerator.generate(X509V3CertificateGenerator.java:434)
at com.android.org.bouncycastle.x509.X509V3CertificateGenerator.generate(X509V3CertificateGenerator.java:412)
at android.security.AndroidKeyPairGenerator.generateKeyPair(AndroidKeyPairGenerator.java:133)
at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.getKeystore(FileSettingsStorage.java:302)
at com.sampleid.sampleid_sdk.common.FileSettingsStorage.writeSecureSettings(FileSettingsStorage.java:185)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSecureSettings(SettingsImpl.java:473)
at com.sampleid.sampleid_sdk.common.SettingsImpl.saveSettings(SettingsImpl.java:321)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettingsToStorage(sampleIDService.java:102)
at com.sampleid.sampleid_sdk.sampleIDService.saveSettings(sampleIDService.java:91)
at com.sampleid.sampleid.features.shared.BaseActivity.onStop(BaseActivity.java:182)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1261)
at android.app.Activity.performStop(Activity.java:6089)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3341)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3390)
at android.app.ActivityThread.access$1100(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Was finally able to solve this. The issue is with the following:
KeyPairGenerator kpg = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, AndroidKeyStore);
KeyProperties.KEY_ALGORITHM_RSA is only available starting API 23, so it fails in APIs before that. Replace it with "RSA"
Also, if you're using SpongyCastle, it should be added using the following approach:
static {
// as per https://github.com/rtyley/spongycastle/issues/27
Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
}
Related
I am getting following exception while user is upgrading from 1 to 3 db schema
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{SplashActivity}: io.realm.exceptions.RealmMigrationNeededException: Realm on disk need to migrate from v1 to v3
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2924)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by io.realm.exceptions.RealmMigrationNeededException: Realm on disk need to migrate from v1 to v3
at io.realm.Realm.createAndValidateFromCache(Realm.java:389)
at io.realm.Realm.createInstance(Realm.java:364)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:346)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
at io.realm.Realm.getDefaultInstance(Realm.java:273)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)**
Realm configuration is as follows:
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
.name(AppConstants.DB_NAME)
.schemaVersion(schemaVersion)
.build();
try {
Realm.migrateRealm(realmConfiguration, new DBMigration()));
} catch (Exception ignored) {
// If the Realm file doesn't exist, just ignore.
}
Realm.setDefaultConfiguration(realmConfiguration);
I have specified DB migrations in code in which i have mentioned all DB changes.
I am using realm version 3.3.0
Can you please help in resolving this issue
Thanks in advance.
issues is with Twitter button, this is working fine with Android 6 Moto G, while on android 5.0.1 Samsung Note 3 it crashes, on Simulator it works fine too,
However my code for Click is,
TwitterLoginButton twitterLoginButton = (TwitterLoginButton) findViewById(R.id.button_twitter);
twitterLoginButton.setCallback(new Callback<TwitterSession>() {
#Override
public void success(Result<TwitterSession> result) {
Log.d(TAG, "twitterLogin:success" + result);
handleTwitterSession(TwitterAuthProvider.getCredential(
result.data.getAuthToken().token,
result.data.getAuthToken().secret), false);
}
#Override
public void failure(TwitterException exception) {
Log.w(TAG, "twitterLogin:failure", exception);
}
});
twitterLoginButton.setOnClickListener(this);
Issues it is showing is,
java.lang.RuntimeException:Unable to start activity ComponentInfo{com.my.project/com.twitter.sdk.android.core.identity.OAuthActivity}: java.lang.IllegalStateException: Unable to extract the trust manager on okhttp3.internal.Platform$Android#2e0793c7, sslSocketFactory is class crittercism.android.q
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.IllegalStateException: Unable to extract the trust manager on okhttp3.internal.Platform$Android#2e0793c7, sslSocketFactory is class crittercism.android.q
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:187)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:60)
at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:718)
at com.twitter.sdk.android.core.internal.oauth.OAuthService.<init>(OAuthService.java:56)
at com.twitter.sdk.android.core.internal.oauth.OAuth1aService.<init>(OAuth1aService.java:69)
at com.twitter.sdk.android.core.identity.OAuthActivity.onCreate(OAuthActivity.java:69)
at android.app.Activity.performCreate(Activity.java:6283)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
i searched a lot on google but unable to find any helpful, solution.
This is a problem with Crittercism. If updating that doesn't help you'll need to report the bug to them.
I am new in Android and I want to put Click event on XML instead of java, and I have implemented following method on Activity class
public void onInfoClick(View v){
switch(v.getId()) {
case R.id.ivAcceptAmericanExpress:
showPopup(v, getString(R.string.apt_american_express));
break;
}
}
and in XML , I have done following code
<ImageView
android:id="#+id/ivAcceptAmericanExpress"
android:layout_width="24.286dp"
android:layout_height="24.286dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/txtAcceptAmericanExpress"
android:src="#drawable/info_image"
android:onClick="onInfoClick" />
but when I click on Image I am getting following error
Could not execute method of the activity
android.view.View$1.onClick(View.java:4021)
android.view.View.performClick(View.java:4781)
android.view.View$PerformClick.run(View.java:19873)
android.os.Handler.handleCallback(Handler.java:739)
android.os.Handler.dispatchMessage(Handler.java:95)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5291)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699):: Cause : java.lang.reflect.InvocationTargetException
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
android.view.View$1.onClick(View.java:4016)
android.view.View.performClick(View.java:4781)
android.view.View$PerformClick.run(View.java:19873)
android.os.Handler.handleCallback(Handler.java:739)
android.os.Handler.dispatchMessage(Handler.java:95)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5291)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
The InvocationTargetException usually points to an exception in the onClick method which you are trying to execute - in your case the onInfoClick method - you can confirm this by commenting out your case-statement and see if you still get the error. Once you have identified the problem - you can make the necessary changes to resolve the exception. You should probably surround the body of the method with a try-catch to be safe.
I am trying to store some data using Cloudmine.
However, I got the error java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory; when I call initialize() for authorization.
I'm not running on a separate thread or something. I'm testing stuff out right now so I just have it so that when a button is clicked, it uploads some information from some EditText fields.
This is my code
public class ButtonClick implements View.OnClickListener {
private MainWindowActivity mainWindowActivity;
public ButtonClick(MainWindowActivity mainWindowActivity, Button doneBtn, Button addBtn) {
this.mainWindowActivity = mainWindowActivity;
addBtn.setEnabled(true);
addBtn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// This will initialize your credentials
// ERROR HERE
CMApiCredentials initialize = CMApiCredentials.initialize("id", "key");
SimpleCMObject location = new SimpleCMObject();
location.add("address", Runner.getAddressStr());
location.add("city", Runner.getCityStr());
location.add("state", Runner.getStateStr());
location.add("zip", Runner.getZipStr());
location.save(new ObjectModificationResponseCallback() {
public void onCompletion(ObjectModificationResponse response) {
Toast.makeText(mainWindowActivity, "Location saved: " + response.wasSuccess(), Toast.LENGTH_SHORT).show();
}
});
EditText address = (EditText) mainWindowActivity.findViewById(R.id.address);
address.setText("");
EditText city = (EditText) mainWindowActivity.findViewById(R.id.city);
city.setText("");
EditText state = (EditText) mainWindowActivity.findViewById(R.id.state);
state.setText("");
EditText zip = (EditText) mainWindowActivity.findViewById(R.id.zip);
zip.setText("");
}
}
This is the Logcat:
Process: prog, PID: 26580
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
at com.cloudmine.api.CMApiCredentials.<clinit>(CMApiCredentials.java:21)
at prog.ButtonClick.onClick(ButtonClick.java:52)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.slf4j.LoggerFactory" on path: DexPathList[[zip file "/data/app/prog-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.cloudmine.api.CMApiCredentials.<clinit>(CMApiCredentials.java:21)
at prog.ButtonClick.onClick(ButtonClick.java:52)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
As I have commented, download zip file from SLF4J distribution and use as library in your project. Then, use slf4j-api-1.7.12.jar (and slf4j-android-1.7.12.jar if needed).
I had the same error and found this solution on github.
Just add the following to your grandle:
implementation 'org.slf4j:slf4j-api:1.7.25'
https://github.com/nomis/slf4j-android
I hade the same problem only on Android 5.0 - 5.1 (a real device and emulators). At that moment, I used Android Studio 2.3.3 and build tools v26.
I solved the problem turning off Instant Run that I didn't use anyway.
Steps:
go to File -> Settings -> Build, Execution, Deployment -> Instant run
Disable it (first checkbox).
UnsupportedOperationException (#DecimalFormatSymbols:getMinusSign:300) {main}
I've translated my app in arabic.
On my devices all is ok, but in Google Analytics I received a lot of this error from arabic users.
On my device all works also when I set my devices into arabic.
Any ideas?
EDIT:
DecimalFormatSymbols nf = new DecimalFormatSymbols();
try
{
nf.setDecimalSeparator(sharedPref.getString("pref_currency_decimal_separator", ".").charAt(0));
nf.setGroupingSeparator(sharedPref.getString("pref_currency_thousands_separator", ",").charAt(0));
formatter_currency.setDecimalFormatSymbols(nf);
final int digits = sharedPref.getInt("pref_currency_decimal_places", 2);
formatter_currency.setMaximumFractionDigits(digits);
formatter_currency.setMinimumFractionDigits(digits);
}
catch(IllegalArgumentException e)
{
currency = "$";
nf.setDecimalSeparator('.');
nf.setGroupingSeparator(',');
formatter_currency.setDecimalFormatSymbols(nf);
formatter_currency.setMaximumFractionDigits(2);
formatter_currency.setMinimumFractionDigits(2);
}
catch(UnsupportedOperationException e)
{ }
Logcat:
java.lang.UnsupportedOperationException: Minus sign spans multiple characters: -
at java.text.DecimalFormatSymbols.getMinusSign(DecimalFormatSymbols.java:300)
at java.text.DecimalFormatSymbols.writeObject(DecimalFormatSymbols.java:611)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1033)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:904)
at java.io.ObjectOutputStream.writeFields(ObjectOutputStream.java:863)
at java.text.DecimalFormat.writeObject(DecimalFormat.java:1129)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1033)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at android.os.Parcel.writeSerializable(Parcel.java:1383)
at android.os.Parcel.writeValue(Parcel.java:1335)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1096)
at android.os.Parcel.writeBundle(Parcel.java:663)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2952)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3568)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
The problem happen only in rtl locales (arabic, hebrew, etc.) after android API 21.
The problem will be fixed in the next releases.
https://code.google.com/p/android/issues/detail?id=170718