java.lang.NoClassDefFoundError on Android with GoogleAccountCredential.newChooseAccountIntent() - android

I am developing for Android 4+ with Eclipse Juno ADT bundle + Google Plugin for Eclipse.
I need to programmatically log into a google account to use the Google Calendar API. For
this I am making use of account manager. I get the following error:
05-05 13:28:55.605: E/AndroidRuntime(11186): FATAL EXCEPTION: main
05-05 13:28:55.605: E/AndroidRuntime(11186): java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker
05-05 13:28:55.605: E/AndroidRuntime(11186): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.newChooseAccountIntent(GoogleAccountCredential.java:171)
05-05 13:28:55.605: E/AndroidRuntime(11186): ...
Here is the code that causes it:
GoogleAccountCredential credential;
credential = GoogleAccountCredential.usingOAuth2(this, CalendarScopes.CALENDAR);
chooseAccount();
private void chooseAccount() {
startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
}
I have searched stackoverflow for solutions. The libs directory contains the calendar
library files for eclipse I imported via google plugin for eclipse (which also put
there the authentication etc... libraries):
android-support-v4.jar
google-api-client-1.14.1-beta.jar
google-api-client-android-1.14.1-beta.jar
google-api-services-calendar-v3-rev41-1.14.2-beta.jar
google-http-client-1.14.1-beta.jar
google-http-client-android-1.14.1-beta.jar
google-http-client-gson-1.14.1-beta.jar
google-http-client-jackson-1.14.1-beta.jar
google-http-client-jackson2-1.14.1-beta.jar
google-oauth-client-1.14.1-beta.jar
gson-2.1.jar
jackson-core-2.1.3.jar
jackson-core-asl-1.9.11.jar
jsr305-1.3.9.jar
These however do not seem to include
com.google.android.gms.common.AccountPicker
If I import this in my code the import line of code is flagged as an error.
So what's up. I've copied this code from the Google Calendar Sample where it
runs just fine:
http://samples.google-api-java-client.googlecode.com/hg/calendar-android-sample/
That code has exactly the same libs except:
calendar lib is rev33 instead of rev41
jackson and jackson-asl libraries are missing
.properties file for each library file present in sample code but not in my code
So this should not be the problem. However,
looking in the imports section of the code, the google calendar sample code has:
import com.google.android.gms.common.GooglePlayServicesUtil;
but if I try to insert this line of code in my code it is tagged as an error
saying the import com.google.android.gms.common.GooglePlayServicesUtil
cannot be resolved.
This post
java.lang.NoClassDefFoundError: com.google.android.gms.common.AccountPicker
says they were able to
import com.google.android.gms.common.AccountPicker;
But I'd like to know what library that came from.
I even tried looking in the original android calendar sample for the
library from which I can include com.google.android.gms.common.*
by inspecting one file at a time but could not find it. How
is it possible?
What am I doing wrong?
Thanks very very much for all your help.

OK, I've found out what I was missing.
Ensure you have downloaded the Android SDK Services -> Extras -> Google Play services
Follow the instructions provided by the following link
to add the google-play-services-lib library to your project:
http://developer.android.com/tools/projects/projects-eclipse.html#ReferencingLibraryProject
Best Regards

I've run into a similar problem lately. My app (not in production yet) would suddenly (since the beginning of May) start throwing uncatchable 'NoClassDefFoundError' error when calling
GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE_FILE)
method. It was happening randomly, usually first time in the morning. I could fix it by re-installing my Google account. Not a good solution for production, though. I've spent frustrating couple of hours trying to resolve it until I finally realized I have another app that does not have the same problem in the same code sequence. So I diff-ed both of them and realized that the "good" one had a different sequence of entries in 'Package Explorer->Project->Properties->Java Build Path' The 'good' one had
'google-play-services.jar' BEFORE
'android-support-v4.jar',
where the 'bad' one had it backwards. So I switched the sequence (using UP, DOWN buttons in the dialog) and it seems to solve the problem. Yet another WT... ? moment! Does anybody have an opinion on this?

Related

Unable to resolve “expo-app-loading” from “App.js”

I am getting this error:
Failed building JavaScript bundle. Unable to resolve
“expo-app-loading” from “App.js”
when I ran my project after a couple of months. Earlier it was working fine but not now.
Can someone please help me out?
If you recently updated SDK versions (expo upgrade), please be sure to review the breaking changes carefully as is advised when you complete the install.
For instance, SDK-40 which was released in December has breaking changes notes about expo-app-loading that probably addresses what you're seeing perfectly.
Read this page : https://blog.expo.io/expo-sdk-40-is-now-available-d4d73e67da33
Look for section title: AppLoading has been extracted from the expo package
There were two problems:
expo-app-loading was not in my package.json, so I just installed it again and boom, it was in my packege.json then.
I was importing 'AppLoading' the wrong way. I wrote
import {AppLoading} from "expo-app-loading"; //wrong way
Which was breaking. Then I corrected it to
import AppLoading from "expo-app-loading"; //correct way
Which solved the issue.

Unity Auth Error With Firebase

I implemented Firebase into a Unity app I am creating. There are two buttons that will run the two functions to create a new user and login an existing user. So far this functionality works on my PC, however whenever I try to deploy it to my android phone or Mac I end up getting the following error in the console.
DllNotFoundException: FirebaseCppApp-5.1.0
Firebase.AppUtilPINVOKE+SWIGExceptionHelper..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for SWIGExceptionHelper
Firebase.AppUtilPINVOKE..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Firebase.AppUtilPINVOKE
Firebase.AppUtil.SetLogFunction (Firebase.LogMessageDelegate arg0)
It appears there is a missing .dll file, however I cannot for the life of me find out how to include it within the project file. I also have double checked the package name and it is the exact same name as the one made for my Firebase project, the google-services JSON in the root of the project, and the Api compatibility level is set to .NET 2.0. On top of that I also uninstalled and reinstalled the app a few times. I also tried using the Play Services Resolver which didn't help much at all either.
Similar error here, only with Firebase Cloud Messaging. After tinkering around in a fashion similar to yours I concluded that it was caused by corruption during import of Firebase Package.
What worked for me:
Deleted each and every folder created while importing Firebase Package.
Reimported Firebase Package

getBuyIntentExtraParams does not exist? aka how do I use Version 6 in-app billing APIs?

The getBuyIntentExtraParams method described by the Android Billing Docs doesn't seem to work properly in my project.
I see that there is an open issue on github that suggests grabbing the AIDL file from the Trivial Drive Android example application, but even after doing this I can't get the v6 API working (I get a cannot find symbol error).
My call is as follows:
Bundle extraParams = new Bundle();
extraParams.putBoolean("replaceSkusProration", true);
String ownedSku = "someSkuAlreadyOwnedByTheUser";
ArrayList<String> replaceSkus = new ArrayList<String>();
replaceSkus.add(ownedSku);
extraParams.putStringArrayList("skusToReplace", replaceSkus);
Bundle buyIntentBundle = mService.getBuyIntentExtraParams(6,
getPackageName(), sku, "subs", "BigOlRandomString", extraParams);
Everything else about billing seems to work fine... what am I missing here?
edit: I can definitely get API v5 working, as Android Studio is more than happy to let me use the getBuyIntentToReplaceSkus function.
Hihi!
It sounds like your build isn't generating the IInAppBillingService.java from the IInAppBillingService.aidl file. Or if it is generating the java file, then the generated version is not being referenced by your project. At the end of the day, the method declaration in the java file is what your code can reference to resolve the cannot find symbol error.
My specific project doesn't use AndroidStudio or gradle, so I can't comment on how to resolve any issues with this step. Google does provide some documentation on it, though: Adding the AIDL file to your project. I believe the directory and file locations need to be very precise for AndroidStudio to pick it up.
Be sure, once you do, resolve the cannot find symbol error that you're passing in an API version of at least 6 to the first parameter.
Hope this unblocks you 8 months later :D good luck!

Android App crash with BaseGameActivity

So, somewhat hard to ask.
I wanna use the google play game service to access a leaderboard for my game.
I tried to use BaseGameActivity like it is shown here Accessing the Games APIs
Tried a few things, did some search but cannot figure out the problem. My App crashes when the BaseGameActivity is started.
Log error shows:
03-10 17:44:54.071: E/AndroidRuntime(31435): FATAL EXCEPTION: main
03-10 17:44:54.071: E/AndroidRuntime(31435): java.lang.IllegalStateException: A
fatal developer error has occurred. Check the logs for further information.
03-10 17:44:54.071: E/AndroidRuntime(31435): at com.google.android.gms.internal.dw$h.b(Unknown Source)
03-10 17:44:54.071: E/AndroidRuntime(31435): at com.google.android.gms.internal.dw$h.b(Unknown Source)
03-10 17:44:54.071: E/AndroidRuntime(31435): at com.google.android.gms.internal.dw$b.bR(Unknown Source)
03-10 17:44:54.071: E/AndroidRuntime(31435): at com.google.android.gms.internal.dw$a.handleMessage(Unknown Source)
Console shows:
[2014-03-10 17:47:18 - BaseGameUtils] Could not find BaseGameUtils.apk!
Answer:
I had to do two metadata entrys about the appid in the manifest.
The Log without filters listed the corresponding errors
The two entries were
<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data
android:name="com.google.android.gms.appstate.APP_ID"
android:value="#string/app_id" />
only one of these entries were mentioned in the tutorial.
I've just finished putting up leaderboards and it was a pain, but I did it and it works. Here's a long list of suggestions that may directly or indirectly help you. I use Eclipse.
For Google Play API, minimum SDK is 9 so put this in your manifest on it's own line:
< uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19"/>
//whatever target you want
Import the BaseGameUtils project to your workspace. You do not have to modify any of this code.
Import google-play-services_lib. This is in your sdk folder. My sdk folder is next to my eclipse folder. Anyways this is in: sdk/extras/google/google_play_services/libproject/google-play-services_lib. You do not have to modify any of this code.
Right Click on YourProject in the package explorer tab (normally on the left side of eclipse with all of your project folders). Then click on Properties (Alt+Enter). Then click on Android. On the bottom part of the Android page, should be "Library." Click the add button and add BaseGameUtils and google-play-services_lib. Do not click "Is Library".
Ensure all of the android-support-v4.jar files in all the relevant projects are using the same up-to-date version. You can update your support file by right clicking your project in the "package explorer" tab and going to ->Android Tools->Add Support Library. Then you accept and update.
You can further check to see if all of the projects listed have this updated jar by right clicking your project and going to properties. Then click on Java Build Path and then Click on the libraries tab. You should see the support jar listed. If not, you can add the jar, where-ever it is located in the project. If you do not do this, you may have something called JAR MIXMATCH. Of course, you will see the exact problem in your console so this is easy to fix and diagnose.
Your manifest should be:
< meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
< meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
The last line with #integer looks into the google_play_services_version so you don't have to do anything in the future whenever the google play version changes. Do not hard code the version number value or you will have to manually update it often.
MyProject extends BaseGameActivity.
Then to call the leaderboard and update it, their sample code of 2 lines of code runs great. See below.
https://developers.google.com/games/services/android/leaderboards
You have to pass in your leaderboard ID given to you when you link up your app to the google play developer console. It's a String that looks something like: "DkbGvageyBASEWEFCx."
Updating and Getting a leaderboard will crash if you aren't connected. Check out this complete sample code below.
//to update
if (getApiClient().isConnected()) //getAPIClient is part of BaseGameUtils
Games.Leaderboards.submitScore(getApiClient(), leaderboardID, score);
//to show
if (getApiClient().isConnected())
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), leaderboardID), 1337);
Lastly, if you are using an app with a different keystore that has a different SHA1 (Secure Hash Algorithm) than the one that you have on the google play store, then there will be an error and you will not be able to connect. So if you uploaded an app with a keystore with an SHA1 like ab:cd:de... and you're debugging your app, you may see problems since Eclipse will use a default android debug keystore which has a different SHA1.
You will not be able to connect and consequently, you will not be able to use any google play services.
I recommend you look at the sample code called "Trivial Quest."
https://github.com/playgameservices/android-samples
It's under eclipse_compat. This sample code shows one how to sign in and unlock an achievement. If you can sign in, you can do achievements and leaderboards really easily.
There's a lot of stuff but you have given us only a small piece of the puzzle. If you have any more problems, please let us know.
I think, maybe, you need put Google Play Services Library in your dependencies,
In this line :
03-10 17:44:54.071: E/AndroidRuntime(31435): at com.google.android.gms.internal.dw$h.b(Unknown Source)
Probally you have problems with maps dependency of google, the library GMS from google is used
to maps and other services from Google Play Services, if you have problems with that, is possible you have added Wrong versions in your project.
The best way for you is, downalod Google Play Services For Games and put in your project
dependencies.
https://developers.google.com/games/services/downloads/
(this google play services is specific to games )

Problems using the EWS Java API on Android

I am trying to use the EWS Java API v1.1.5 (http://archive.msdn.microsoft.com/ewsjavaapi) in an Android application, and have run into a number of issues.
I downloaded the source, and followed the instructions provided to compile the EWS Java API in Eclipse. In those instructions you are told to download and
add the following pre-requiste jar file dependencies:
commons-codec-1.4.jar
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
jcifs-1.3.15.jar
I did this, and followed the build instructions with produced the following jar files:
EWSAPI-1.1.0.jar
EWSAPIWithJars-1.1.0
Next, I built a brand new Android application, added the appropriate permissions to the manifest, and then added the following source to the primary activity's OnCreate:
ExchangeService service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials("emailaddress", "password");
service.setCredentials(credentials);
try
{
service.autodiscoverUrl("emailaddress", this);
}
catch (Exception e)
{
e.printStackTrace();
}
I first tried running this application with the EWSAPI-1.1.0.jar file as a dependency. When I did that, I obtained the following fatal error:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.NoClassDefFoundError:
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager at
microsoft.exchange.webservices.data.ExchangeServiceBase.(Unknown
Source) at
microsoft.exchange.webservices.data.ExchangeServiceBase.(Unknown
Source) at
microsoft.exchange.webservices.data.ExchangeService.(Unknown
Source) at
com.meshin.exchange.ExchangeDiscoveryActivity.onCreate(ExchangeDiscoveryActivity.java:40)
From what I've researched, it seems like this error is being generated because Android comes with the Apache HttpClient 4.0, which doesn't appear
to have the MultiThreadedHttpConnectionManager class anymore.
If I instead remove the EWSAPI-1.1.0.jar, and instead use the EWSAPIWithJARS-1.1.0.jar file as a dependency, I get the following error:
VFY: unable to resolve static method 908: Ljavax/xml/stream/XMLOutputFactory;
newInstance()Ljavax/xml/stream/XMLOutputFactory;
VFY: dead code 0x0008-006a in L
microsoft/exchange/webservices/data/EwsUtilities;.formatLogMessage
(Ljava/lang/String;Ljava/lang/String;) Ljava/lang/String;
VFY: unable to find class referenced in signature (Ljavax/xml/stream/XMLStreamWriter;)
And then eventually...
FATAL EXCEPTION: main java.lang.VerifyError:
microsoft.exchange.webservices.data.AutodiscoverService at
microsoft.exchange.webservices.data.ExchangeService.getAutodiscoverUrl(Unknown
Source) at
microsoft.exchange.webservices.data.ExchangeService.autodiscoverUrl(Unknown
Source) at
com.meshin.exchange.ExchangeDiscoveryActivity.onCreate(ExchangeDiscoveryActivity.java:41)
I am assuming because now I am including the HttpClient 3.1 jar and it is conflicting with the HttpClient 4.0 jar included with the Android libraries.
My question is if there is a way for me to use the EWS Java API in an Android project without having to re-write the parts of it which reference
HttpClient 3.1-specific things which are no longer in 4.0.
You can use microsoft's EWS api for android by doing the following steps,
download the source code available in the URL,
http://archive.msdn.microsoft.com/ewsjavaapi
EWSJavaAPI_1.1.5.zip
Make the changes to above api to work for JDK 1.4 in eclipse like remove override annotations e.t.c
Download source code of javax.* package available in below URL,
http://www.java2s.com/Code/JarDownload/jsr173/jsr173_1.0_src.jar.zip
Download source code of stax api available in below URL,
http://dist.codehaus.org/stax/distributions/stax-src-1.2.0.zip
Keep all the sources under the single java project in eclipse
Open the project explorer and select the package which are starts with "javax" and rename to your company name eg: com. Note: Eclipse will ask for all the naming contexts will change then click OK.
Export all the java sources to one single jar file.
Then You good to go to use the jar in Android application with out any problems.
I used the same way explained above and it worked in android application 100% perfectly.
This isn't a useful answer but I've also been struggling to look at the EWS API over the last couple of weeks, with no success.
The main issue I've found is it references a lot of the javax APIs which aren't on Android. There's a hack you can find that explains how to "re-class" these but I've not got it working yet; in addition, the DnsClient references some namespaces that jarsearches only return for rt.jar - the main runtime. And including this in an Android app would just be crazy!
Before finding the API I was trying to use KSOAP to communicate with EWS but again ran into problems - you need to be able to do NTLM and SSL and I couldn't find any way of combining all these with KSOAP in any simple way.
The EWS API looks the way to go (why re-invent the wheel) but getting it working on Android looks very tricky (if not impossible)
Please check this library for the solution

Categories

Resources