Cannot Resolve Symbol 'analytics' When Using Google Analytics - java

I am trying to implement Google Analytics in my app,
I have already created a global_tracker.xml file containing the basic configuration and my Property-ID.
I have added the meta-data tag to my AndroidManifest.xml:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
These are the dependencies in my build.gradle file:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:21.0.0'
compile 'com.google.android.gms:play-services:6.1.+'
}
I have created a class to store my tracker Enum as instructed in the Google Analytics SDK V4 Guide
But even after all of these steps, when attempting to import:
import com.google.android.gms.analytics.Logger;
import com.google.android.gms.analytics.Tracker;
import com.google.android.gms.analytics.GoogleAnalytics;
I get an error saying "Cannot resolve symbol 'analytics' directing me to my import lines.
I have tried searching on the internet and in SO for a solution but didn't succeed.
What am I missing?

Eventully I found out what the issue was, my Android Studio project name had an exclamation mark (!) in it, causing the google play services to fail to attach itself to the project, making me unable to use the Google Analytics Library, aswell as other .jar files I wanted to add manually.
Long story short, use the tips Android Studio displayes when you create a new project: avoid spaces and special characters when creating your project and developing it, as it might fail to work as expected

Related

Cannot import a Library from GitHub into Android Studio

I tried to add this library: https://github.com/WojciechZankowski/iextrading4j into android studio, it is a library to retrieve realtime stock data from the IEXTrading API but when I did, or atleast I think I imported it the right way, I got a bunch of errors like MultiDex errors and findbugs:jsr305:1.3.9.
I tried to use the release version 2.1.1, then 2.0.1. Can someone please walk me through the process of how to set it up?
Error:
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't write [C:\Users\Ashwin\AndroidStudioProjects\sockettesting\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\USER\AndroidStudioProjects\sockettesting\app\build\intermediates\transforms\desugar\debug\49.jar(;;;;;;**.class)] (Duplicate zip entry [49.jar:javax/inject/Inject.class]))
I've tried searching for answers on how to solve these errors but I got nowhere, I tried multiDexEnable true in gradle and more.
I had a similar problem. I could not get the iextrading4j library to work either, even in a blank project. I changed my dependencies entry to this...
implementation group: 'pl.zankowski', name: 'iextrading4j', version: '2.3.0', ext: 'pom'
Then it worked just fine!

How to access aar file, in libs, from Main

I spent the last three days trying to read an .aar in Android Studio and I just can't figure it out.
My project view looks like this:
--- AnApplication
----------------------.gradle
-----------------------.idea
----------------------- app
-------------------------------- build
-------------------------------- libs
---------------------------------------- cube5-debug.aar
(...)
I want to access a class inside cube5-debug.aar from my main activity.
I know the class is there in the .aar file.
I don't know the precise import line I must write at the start of my main.
I have tried import com.company_cube.cube5 (the package of the project where I generated my .aar) and many other variants.
I don't know if Android Studio is recognizing the file as a library. However, the files sync with the gradle successfully.
(For context, the project where I generated the .aar was made by Unity, by exporting a Unity project into an Android one, and then generating the .aar from that one; the goal was to use this .aar file as a library in a second Android Studio project - the one I am talking about in this post)
I am patiently waiting for any help you can give me. Thanks
EDIT: To import the .aar, I followed the images of this small post:
Importing .aar in android Studio
And solved the error the post reports by putting the .aar in the libs folder like Daniel Nugent said. However, when I try to write, in the Main:
Intent intent = new Intent(getApplicationContext(),UnityPlayerActivity.class);
AS doesn't recognize UnitPlayerActivity. This class is inside the .aar file supposedly. Before making the aar in my first AS project, it was here:
cube5->libs->unity-classes.jar->com.unity3d.player->UnityPlayerActivity
When I open the .aar with Winrar, and open unity-classes.jar with a text editor, I see a almost everything as encoded symbols.
I'm not sure it is normal. Any idea?
EDIT 2: I think I know where the error is: when I import my .aar, I get an IDE fatal error. I don't know how to solve it, so if you can, please check the post I made about it:
IDE fatal error on importing .aar
For android Studio 2.3.3 you can use
repositories {
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile(name: 'cube5-debug', ext: 'aar')
}
in the app level build.gradle. I did't check it for AS 3.0.
Add .aar file to your app by doing:
in project build.gradle
allprojects {
repositories {
flatDir {
dirs 'libs'
}
}
}
in app build.gradle
dependencies {
compile(name:'cube5-debug', ext:'aar')
}
So I managed to solve it. The .aar file I talked about was exported with AS, after I imported an Unity project into AS. I did this in order to use the Unity program inside AS. However, this gives error for some versions of Unity and AS. I installed Unity 5.5.0f3 and an older version of AS, and everything worked fine.
Note1: if you aim to install that Unity version, you will be prompted with a requirement of some windows 10 tool, which you must get (I cannot remember the name). I did it by downloading windows 10 install and installing only that tool, which comes with the package.
Note2: I made the program from Unity work inside AS but only because it was a simple program. I later wanted to do an Augmented Reality App in Unity, and use it in AS, but it cannot be done apparently. Evertyting works fine until I import the .aar into AS, and a class in that .aar library gets unresolved ("Video player”). This should have to do with the AR camera class, which AS does not recognize. I ended up creating a AR app with Unity, another app in AS, and from the AS app, calling the Unity app with two lines of code, whenever necessary. To return to the AS app, now in background, I simple click the back button, which is recognized by the Unity app (if you make code in Unity for it) and makes it destroy itself, returning to the AS app.

Using AppEngine's DatastoreService in Android Studio

I'm trying to make a simple Android app that writes, for example, an entity with a key called "Example" and a value of "Hello World". Following the tutorial here I've created and uploaded a backend and got the basic functionality detailed there to work using the Java Servlet module, but it wouldn't save any entity on the datastore (but rather just make a toast on the client app) so it was useless for my purposes.
So now I'm trying to import the DatastoreService and Entity classes so I could use the method DatastoreService.put(Entity). However, conflicting resources on the internet and myself being unable to find a coherent guide about this process caused multiple compile errors:
Adding the following dependencies to build.gradle (app):
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.1'
compile 'com.google.appengine:appengine-endpoints:1.9.1'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.1'
compile 'javax.servlet:servlet-api:2.5'
Raises the error:
Gradle DSL method not found: 'appengineSdk()'
Adding the following dependency to build.gradle (project):
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.3'
And applying the plugin in the same file:
apply plugin: 'appengine'
Raises:
Error: Task with name 'assemble' not found in root project
I'm looking for clear instructions on how to properly implement the appropriate classes and handle the process as I'm very new to this aspect of Android Studio and it seems I've gone off-track. Thanks for your support.

Google Maps v2 in the Android Studio. Not found GeoPoint

I am working on a code that was made in the Eclipse and i am migrating to Android Studio, however i am having a problem to the to import
com.google.android.maps.GeoPoint;
but i can import
com.google.android.gms.maps.GoogleMap;
I've tried to add in my Gradle file
compile 'com.google.android.gms:play-services:6.5.87'
and also i've tried also to use .jar, however i didn't have good results.
compile files('libs/google-play-services.jar')
I searched about this in many places, but i found nothing to help me, case somebody have resolved this problem and want help me i thank you.
To work, i had that to replace the below line in the my Gradle file.
android {
...
compileSdkVersion 16
...
}
To
android {
...
compileSdkVersion "Google Inc.:Google APIs:16"
...
}
Please following all the steps to Add Google Play Services to Your Project in Android Studio:
1.Open the build.gradle file inside your application module directory.
Note: Android Studio projects contain a top-level build.gradle file and a build.gradle file for each module. Be sure to edit the file for your application module. See Building Your Project with Gradle for more information about Gradle.
2.Add a new build rule under dependencies for the latest version of play-services. For example:
apply plugin: 'com.android.application'
...
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
Be sure you update this version number each time Google Play services is updated.
Note: If the number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them. For information on how to do this, see Selectively compiling APIs into your executable.
3.Save the changes and click Sync Project with Gradle Files in the toolbar.
4.Open your app's manifest file and add the following tag as a child of the element:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
You can now begin developing features with the Google Play services APIs.
Please refer to here for more details.

Unable to execute dex: Multiple dex files define Lbolts/AggregateException

I do know Multiple dex problems have been reported a lot of times before, but none of the solutions seems to work in my case.
Console:
Unable to execute dex: Multiple dex files define Lbolts/AggregateException;
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lbolts/AggregateException;
One of the popular solutions is unmarking the 'Android private libraries' container from buildpath. I cannot do that because there are a few more libraries in that container that i need.
Another solution is unmarking any duplicate library explicitly added in .jar form. I have no such libraries.
The duplicate library in my case is: android-support-v7-appcompat.jar
I have it (directly referenced from the sdk folder) in these two containers:
1.) Android Private Libraries
2.) Android Dependencies
The problem is that i just cannot untick any of these two containers completely, because both of them contain other necessary libraries. But i also am unable to remove just this duplicate .jar file from either containers.
EDIT:
N.B. When i add the android-support-v7-appcompat library_project to my project, it enters into both containers. There must be some way so that goes into only one.
Can any one help me how i can do it?
RESOLVED
bolts-android library was the real trouble here. There were two different versions of it causing a conflict. The FacebookSDK library brings bolts-android-1.1.2, and android-support-v7-appcompat brings bolts-android-1.1.4.
I unmarked Android Private Libraries container in the FacebookSDKlibrary project, which contained bolts-android-1.1.2. As a result, my project now had only one version, bolts-android-1.1.4, settling the conflict. It runs fine now.
Also, turns out, the duplicate android-support-v7-appcompat entries were not an issue.
i encountered this recently on my react native project, you can go to your android folder of your project . and in terminal hit this command "./gradlew app:dependencies" to see dependencies tree. i found two package for android bolts under facebook sdk . if you exclude this package from facebook sdk things will work fine again
compile ('com.facebook.react:react-native:+') {
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}
This can happen when adding facebook SDK to Android, you can solve it with:
compile ("com.facebook.android:facebook-android-sdk:4.1.0") {
exclude group: 'com.parse.bolts', module: 'bolts-android'
}
as react version has updated to 0.31.0,when you want to integrate com.facebook.fresco:animated-gif:0.10.0 which has com.parse.bolts has well,you may do like this:
compile ('com.facebook.react:react-native:+') {
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}
compile ('com.facebook.fresco:animated-gif:0.10.0'){
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}

Categories

Resources