Adding google analytics to an android app - android

I have a working android app and now want to add google analytics to it. I am following the instructions here:
http://code.google.com/mobile/analytics/docs/android/
When I add the import statement:
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
I get the error:
The import com.google.android cannot be resolved
I have created a libs directory in the project and placed the libGoogleAnalytics.jar file in it. I tried adding this to the AndroidManifest.xml:
<uses-library android:name="com.google.android.analytics" />
I have tried opening and closing Eclipse and doing 'Project / Clean'. Nothing seems to affect the problem. I am somewhat new to Java. What am I missing?

I think you should add library libGoogleAnalytics.jar to build path (in libs right click on libGoogleAnalytics.jar -> BuildPAth -> Add to Build Path)
Do not add anything in Manifest file and in your java file use cmd+Shift+O(for Mac, for Windows Ctrl+Shift+O) to automatically organize your imports)

Related

R.java file cannot be resolved after importing Google Play Services

I have created an Android app in that when I imports Google Play Services library it removes R.java file.
I had clean and build the project and also restarts the eclipse but can't get the R.java file.
How to solve this problem?
Thanks.
As mentioned here : https://developer.android.com/google/play-services/setup.html#Setup
Here's different steps to proceed for setting up Google Play Services :
Copy the library project at /extras/google/google_play_services/libproject/google-play-services_lib/ to the location where you maintain your Android app projects.
Import the library project into your Eclipse workspace. Click File > Import, select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
In your app project, reference Google Play services library project. See Referencing a Library Project for Eclipse for more information on how to do this.
Note: Don't forget to copy the library to your development workspace :
check your resource file error.
after solving your resource xml file error remove import android.R; from your java file and import com.your.package.name.R; in your java
Finally I got the solution myself.
I just changed the android:minSdkVersion="8" to android:minSdkVersion="14" in AndroidManifest.xml file and problem solved.
Thanks.

eclipse android can not import google play services library

hello i am quite new to Android development and i want to learn how to use the google Maps API v2. After trying numerous tutorials, i always seem to have a problem with the google play services library. Somehow, Eclipse can't import it properly. I tried this tutorial https://github.com/thecodepath/android_guides/wiki/Google-Maps-Fragment-Guide and when i try to include Google Play Services project as a library, first it all goes nice and smooth, i get a green tick in the Project Properties - Android - Library window, but when i close it i still get lots of "can't be resolved to a type" errors. I return to the window where i add the library and i see a red "X" and a question mark under "project" instead of the green tick. I tried several other tutorials and i always have a problem with this library. I like this tutorial and i would really like to make it work. I also tried to manually copy the library folder in the workspace but that didn't work either. I googled like crazy trying to find an answer but i always find something that i tried before (like manually copying the library in the workspace or something similar). I am quite desperate, i really have no idea why it can't just see the library please help. Also this is my first post to StackOverflow so be gentle :)
later Edit (solved):
when i imported the downloaded project, i kept it on the desktop and thats why it didn't work, after i copied it in the workspace everything worked. Thank you all very much for helping a beginner :)
The important thing in adding a library in eclipse is to remember that your project and the library project need to be in the same workspace.
To solve this follow below ways,
You can copy the google-play-services library project to the same workspace where your main project is there.
else
While importing the library to eclipse remember to check copy projects into workspace which will add a copy of the library to your workspace.
I see a red "X" and a question mark under "project" instead of the
green tick.
The problem is -
The path to your google play services library is not same as the path to your project. It is outside of your project. And so is not recognized by simple import.
Solution - Put the library in the project's libs folder.
NOTE: Just putting the library to the libs folder is not enough.
After you added your library follow these steps -
1) Go to Project -> Properties -> Java Build Path -> Libraries -> Add JARs..
2) Now add your recently added jar to the build path from JAR selection process.
3) Go to Project -> Properties -> Java Build Path -> Order and Export.
4) Put a tick mark in the check box against this library name and press OK.
5) Do Project -> Clean.
if your giving google-Play-Service-lib as a references to your project , try to keep your project and the Google-play services lib should be in same drive.
if your project is on C: drive means place Google-play-services-lib in C:
While making the copy of the entire folder libproject containing google-play-services_lib from eclipse import project by selecting the copied libproject folder in your working place.
For the rest follow the steps in Setting Up Google Play Services
Eclipse
Copy the library project at
<android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/
to the location where you maintain your Android app projects.
Import the library project into your Eclipse workspace. Click
File > Import, select Android > Existing Android Code into Workspace
and browse to the copy of the library project to import it.
After you've added the Google Play services library as a dependency for your app project, open your app's manifest file and add the following tag as a child of the <application> element:
< meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Android Studio
Open the build.gradle file inside your application module directory.
Add a new build rule under dependencies for the latest version of play-services
eg
...
dependencies {
compile 'com.google.android.gms:play-services:9.2.0'
}
apply plugin: 'com.android.application'
Source developers.google.com

Eclipse doesn't recognize already existent projects I'm attempting to import and improperly imports projects?

I'm using Eclipse Indigo and I'm using it for the purpose of developing Android mobile apps. I'm attempting to import the new version of the ActionBarSherlock library to use with a project I've already got. I've tried to go to File > Import... > Existing Projects but that doesn't find anything and I've also tried doing File > New > Android Project > From existing source but it only imports like half the resources folder and that's about it. It doesn't import any other files and it even leaves out the AndroidManifest.xml file which is obviously a key file here. Any help out there for me or am I stuck? :-/
Drop the jar into your /workspace/<appname>/libs folder. Go back into Eclipse, right-click on your project and choose refresh (verify that a new folder appears in your project). Next, go into Menu->Project->Properties [Java Build Path]. Choose Libraries tab then [Add Jars...] and finally browse to your libs folder. Your new jar should be available.
You may need to add that library as an external library and then reference it in your manifest file similar to how we implement the GoogleAPI for maps.
<uses-library android:name="com.google.android.maps" />
If that doesn't so it the next thing I'd try is to copy/paste that project under your apps project folder. You'll have to go into that project and resolve the "package" names to reflect your own package names. Once you do that, all those classes will be visible in your project. You may need to manually merge resources if there are conflicts.

How to resolve javax.xml.bind.* imports in Eclipse? [duplicate]

In my Android app I use:
import javax.xml.bind.JAXBContext;
But I get:
The import javax.xml.bind cannot be resolved
I do have com.viewstreet.java.eclipse.jaxbplugin.JAXBPlugin in my plugins list.
#commonsware is correct , just add respctive JAXB API jars in lib folder of your projet or in case of maven project add dependency in pom file
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
viz in my case on linux, solved the issue
Go to https://javaee.github.io/jaxb-v2/ and download the standalone distribution (link at the very bottom of page).
jaxb-ri-2.3.1.zip or whatever version is the latest shall be downloaded. Unzip it and copy the jaxb-ri\mod\jaxb-api.jar from the unzipped folder into the plugins folder of your eclipse installation directory.
Go to eclipse, open your project, right click project name in Projects panel (left most) and choose Properties => Build Path
Under Libraries tab, select Classpath and then click Add External JARs button. Browse and select the file you just copied to eclipse's plugins folder.
Click Apply and Close
Just import your required javax.xml.bind classes and your project shall be built instantly.
Put the JAR in the project's libs/ directory, then add it to the build path via the Add JARs button. That's my standard recipe, and it seems to work, and it has the advantage of putting the JAR in the right spot for command-line builds as well.
At this point, though, I suspect that you will get a compile error. Generally, you cannot import classes in the java and javax packages into an Android project.
Download jax-b.jar and add it as external jar in your project.
Any import cannot be resolved in Java means a class you referenced is not found anywhere on the classpath. You need the library you're trying to use added to your classpath. In Eclipse, that's in project properties in the Java Build Path => Libraries tab. If you don't have the jar file that contains the API you're trying to use, you probably need to get it from http://jaxb.java.net/.
Adding a library/JAR to an Eclipse Android project

How to resolve javax.xml.bind.JAXBContext in Eclipse?

In my Android app I use:
import javax.xml.bind.JAXBContext;
But I get:
The import javax.xml.bind cannot be resolved
I do have com.viewstreet.java.eclipse.jaxbplugin.JAXBPlugin in my plugins list.
#commonsware is correct , just add respctive JAXB API jars in lib folder of your projet or in case of maven project add dependency in pom file
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
viz in my case on linux, solved the issue
Go to https://javaee.github.io/jaxb-v2/ and download the standalone distribution (link at the very bottom of page).
jaxb-ri-2.3.1.zip or whatever version is the latest shall be downloaded. Unzip it and copy the jaxb-ri\mod\jaxb-api.jar from the unzipped folder into the plugins folder of your eclipse installation directory.
Go to eclipse, open your project, right click project name in Projects panel (left most) and choose Properties => Build Path
Under Libraries tab, select Classpath and then click Add External JARs button. Browse and select the file you just copied to eclipse's plugins folder.
Click Apply and Close
Just import your required javax.xml.bind classes and your project shall be built instantly.
Put the JAR in the project's libs/ directory, then add it to the build path via the Add JARs button. That's my standard recipe, and it seems to work, and it has the advantage of putting the JAR in the right spot for command-line builds as well.
At this point, though, I suspect that you will get a compile error. Generally, you cannot import classes in the java and javax packages into an Android project.
Download jax-b.jar and add it as external jar in your project.
Any import cannot be resolved in Java means a class you referenced is not found anywhere on the classpath. You need the library you're trying to use added to your classpath. In Eclipse, that's in project properties in the Java Build Path => Libraries tab. If you don't have the jar file that contains the API you're trying to use, you probably need to get it from http://jaxb.java.net/.
Adding a library/JAR to an Eclipse Android project

Categories

Resources