google play game service error -> 'Could not find class...GameHelper ' - android

import com.google.example.games.basegameutils.GameHelper;
public class MyAppName extends Cocos2dxActivity implements GameHelper.GameHelperListener {
....
.....
public static GameHelper gameHelper;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
gameHelper = new GameHelper(this);
.....
error point: gameHelper = new GameHelper(this);
error Message : Could not find class 'com.google.example.games.basegameutils.GameHelper', referenced from method com.company.MyAppName.MyAppName.onCreate
How do I fix this?

On BaseGameUtils, go to Project Properties | Android. Verify that it's targeting a valid Android target that's present on your SDK (anything with API level >= 8 should work).
Also on the project properties screen for BaseGameUtils, check that the "Is Library" checkbox is checked.
Check that BaseGameUtil is referencing google-play-services_lib as a library. (Project Properties | Android | References).
Check that your project is referencing BaseGameUtil as a library (same).
Hope this helps!

Did you define Basegameutils as a library project and include it as a reference ?
The doc that accompanies the sample is fairly good.

In the latest BaseGameUtils project (I downloaded from google github on Aug 13, 2014), the source files are not under the src/ folder. so you will need to Properties->Java Build Path->Add folder and select the java folders.
If the project then compiles without error for the BaseGameUtils, great! I also encountered some other compilation errors and solved it by update the Google Play services to the latest version in SDK manager.
Hope it helps.

Related

Setting up JNA in Android Studio

I try to import jna.jar into my project since JNA is a very useful tool to call Native library which is base on JNI.
OS: Windows 10
IDE: Android Studio 1.5.1
JDK: 1.8.0_73
NDK: r10e
What I have done
(AS = Android Studio)
Create a new project by AS with API18.
Download jna.jar from their GitHub.
https://github.com/java-native-access/jna
copy jna.jar into project folder.
JNATest\app\libs\jna.jar
In AS, right-click on the icon of jna.jar, choose Add as Library
Wait for few seconds, check the File->Project Structure->app->Dependencies. We do have the jna.jar. (Same as app\build.gradle)
build gradle
Implement JAVA code about JNA in MainActivity.java
Run app on real device Sony Z3 (arm)
Crash by CLibrary.Instance.printf("Hello, JNA");
Error Message on Android Monitor
E/AndroidRuntime: FATAL EXCEPTION: main
Process: i3d.jnatest, PID: 1068
java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-arm/libjnidispatch.so) not found in resource path (.)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:866)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:826)
at com.sun.jna.Native.<clinit>(Native.java:140)
..
... so on
Java code
package i3d.jnatest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.sun.jna.Library;
import com.sun.jna.Native;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CLibrary.Instance.printf("Hello, JNA");
}
public interface CLibrary extends Library
{
CLibrary Instance = (CLibrary) Native.loadLibrary("msvcrt", CLibrary.class);
void printf(String format, Object... args);
}
}
Question
According to error message, I miss /android-arm/libjnidispatch.so in runtime.
Did I put the wrong place for jna.jar?
How should I get and use /android-arm/libjnidispatch.so?
I am a newbie about Android Studio, so maybe misunderstanding something key-point.
For Android, reference the JNA library adding #aar at the end of the string instead of downloading the JNA jar:
https://github.com/java-native-access/jna/blob/master/www/FrequentlyAskedQuestions.md#jna-on-android
Put the .so file in the following directory (when using android studio): yourproject\app\src\main\jniLibs\armeabi-v7a\libjnidispatch.so
Update I: (up to version <= 4.3.0) Since some of you asked where to find the *.so file:
On the official JNA site you will find all the supported architectures (30+) for download:
https://github.com/java-native-access/jna/tree/master/lib/native
Download the jar of the architecture you'd like and open it with some zip tool. In there you'll find the libjnidispatch.so file (of course only for unix architectures. For windows its a dll)
Update II: (starting from version >= 4.4.0)
Use the jna-X.X.0.aar file, supplied by the JNA project
As mentioned in a comment - starting from version 4.4.0 JNA publishes an AAR to maven central with all the libjnidispatch.so's in it. Users have had better luck using gradle than straight maven here, which doesn't always select or properly handle aars.
I found this comment in a file in the library github repo - "If you're using Google's Eclipse plugin then you must manually remove libjnidispatch.so from jna.jar/lib/armeabi and add it into your project's libs/armeabi directory."
Since this file was created in 2012 and Android Studio was still in very early phase and not super popular by that time, I assume it might be a valid note for Eclipse and also for Android Studio. I suggest you try it.

How to setup alljoyn sdk in android?

I am trying to setup two android devices to communicate with each other through wifi. Some of the links I have gone through suggest alljoyn sdk in order to accomplish this.
There is an sdk download but there is no documentation for how to setup environment.
Here is how to set up an AllJoyn SDK development environment with android studio:
Download the SDK from this page. Go for Android Core SDK - release (or debug).
Create a new blank android project.
Create directory <project>/app/src/main/jniLibs and <project>/app/src/main/jniLibs/armeabi.
From alljoyn-15.09.00-rel/java/jar copy alljoyn.jar and from alljoyn-15.09.00-rel/java/lib copy liballjoyn_java.so. The directory to copy from might differ depending on the current version and your release/debug choice.
Put alljoyn.jar in /jniLibs and put liballjoyn_java.so in /jniLibs/armeabi. Should look like this
Right click project -> Open Module Settings -> app -> Dependencies.
With the green [+] button, add a file dependency.
Navigate to <project>/app/src/main/jniLibs/alljoyn.jar and select that jar.
This will add a line in your gradle (compile files('src/main/jniLibs/alljoyn.jar')) that will allow for code completion etc.
In the file where you want to use alljoyn code, include this snippet
/* Load the native alljoyn_java library. */
static {
System.loadLibrary("alljoyn_java");
}
for example:
public class MainActivity extends AppCompatActivity {
/* Load the native alljoyn_java library. */
static {
System.loadLibrary("alljoyn_java");
}
#Override
public void onCreate(Bundle savedInstanceState) {
...
}
}
You can now use the alljoyn SDK. Import classes with
import org.alljoyn.bus.BusAttachment;
import org.alljoyn.bus.BusException;
import org.alljoyn.bus.BusListener;
etc.
If you're more of an eclipse guy, check this official documentation page on how to setup an eclipse environment.

What is the minimum number of steps to get full javadoc support with the new default project options?

With the new SDK Tools and ADT versions 22.6.2, the default options for creating a new project with a blank activity produces a project which uses Fragments and refers to a library project (a new one for each project) named appcompat_v7_x.
The relevant parts of the stub code for the main activity are:
package com.myname.miniandroid;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
.....
.....
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
....
}
public static class PlaceholderFragment extends Fragment {
......
......
}
}
.
We can see that it uses a Fragment and an ActionBarActivity. The automatically created library project has both the v4 and the v7 jars in its libs folder, the main project has just the v4 jar. As built by default, hovering over either of these classes gives no javadoc information.
To get such support I've had to :
1) insert a file android-support-v7-appcompat.jar.properties into the libs folder of my automatically created appcompat_v7_4 library project. It contains the lines:
doc=c:\\dev\\tools\\android-sdk-windows4.4\\docs\\reference
src=C:\\dev\\tools\\android-sdk-windows4.4\\extras\\android\\support\\v7\\appcompat\\src
(Both lines seem to be necessary)
2) insert a file anndroid-support-v4.jar.properties into the libs folder of the main project. It contains the line:
src=C:\\dev\\tools\\android-sdk-windows4.4\\extras\\android\\support\\v4\\src
3) Close and reopen both projects and clean all projects.
I've got a brand new installation of Eclipse Kepler and an up to date installation of the SDK.
I feel that there must be a quicker way of getting set up to start a new project with the recommended default options. If anyone can tell me what it is, I would be most grateful.
You have use the "New" button in the upper left corner, select Android Application Project, choose the name, icon...
When you have done, you should have a working "Hello world" app.
If you want to add external libraries this is the answer: https://stackoverflow.com/a/3643015/3203988

Error google-play-services_lib\AndroidManifest.xml not found or not a file with Robolectric 2 and Google Play Services (maps V2)

I have an Android application with Google Maps V2 configured with maven in Eclipse. So I have a "mavenised" Google Play Services lib in the worspace, and the app pom has two maven dependencies to google-play-services jar and apklib.
I implemented a dummy test which only checks if a map fragment is not null:
#RunWith(RobolectricTestRunner.class)
public class MapsTest {
private GoogleMap map;
private ElementMapActivity activity;
#Before
public void setUp() throws Exception {
activity = new ElementMapActivity();
activity.onCreate(null);
}
#Test
public void mapExists() {
// Try to obtain the map from the SupportMapFragment.
map = ((SupportMapFragment) activity.getSupportFragmentManager()
.findFragmentById(R.id.elementMap)).getMap();
Assert.assertNotNull(map);
}
}
Note: a similar code is used in the real application activity to show the map, and it runs OK.
I don't implement any custom testrunners.
I run the test with maven: mvn test.
With Robolectric 1.2 the test builds and executes, but the assertNotNull fails, as the map instance is null. The fragment is not correctly recovered.
With Robolectric 2.1.1 the test builds but fails to execute. I get an exception for each test in the project (not only for the one that tests the maps):
WARNING: no system properties value for ro.build.date.utc
java.lang.RuntimeException: .\..\google-play-services_lib\AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml
at org.robolectric.AndroidManifest.validate(AndroidManifest.java:108)
at org.robolectric.AndroidManifest.getResourcePath(AndroidManifest.java:274)
at org.robolectric.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java:280)
at org.robolectric.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java:282)
at org.robolectric.RobolectricTestRunner.createAppResourceLoader(RobolectricTestRunner.java:576)
at org.robolectric.RobolectricTestRunner.getAppResourceLoader(RobolectricTestRunner.java:568)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:89)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:387)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:227)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:120)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:103)
at org.apache.maven.surefire.Surefire.run(Surefire.java:169)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
It seems that Robolectric tries to use the google-play-services library manifest instead of the main application manifest, which is in the default location: the app root folder. The library manifest is in it's own root folder as well.
Am I missing some configuration for the tests? Should I use a custom testrunner? Or is it that Google Maps V2 are not supported with Robolectric 2?
Edit: I can do without the maps tests. The problem is that with Robolectric 2 all the other tests get this error too, just by having the google-play-library dependency, so I can not use Robolectric 2 by now. I would like to know if this is a known bug in order to decide to go back to Robolectric 1 or not. I checked Robolectric bug reports and didn't find anything about this.
I have recently encountered the same problem with ActionBarSherlock when running my Robolectric tests under my Maven build plan.
The problem was not evident when I was completing builds on a Windows machine and only became apparent after I switched my laptop for a OSX power device.
I found that the problem was that the library name "google-play-services_lib" doesn't (exactly) match that of the folder name in the directory structure. In my case, my Eclipse project was called "ActionBarSherlock-4.3.1" whereas the folder itself was called "actionbarsherlock" under the file system.
I recommend that you synchronise the two names (Eclipse project and file system) and re-run your tests. Hope that helps.
Testing Android Apps, with Robolectric 2.1.1, that use google-play-services_lib (Google Maps) produces AndroidManifest.xml not found RuntimeException.
The short answer is here in bold. The long answer is below it.
Look in your project for a file named project.properties
Create a new file called test-project.properties
Override any or all of the android.library.reference.$
For example in my project.properties it had this library reference:
**android.library.reference.1=../../../ADK/adt-bundle-windows-x86_64-20130522/sdk/extras/google/google_play_services/libproject/google-play-services_lib**
I overrode it in the test-project.properties file
android.library.reference.1=res
Put the AndroidManifest.xml from the google-play-services_lib into the res(or any folder in the project) folder of the project you are testing
The long answer:
I was having the same issue and was thinking the problem was the same as described above "google-play-services library manifest instead of the main application manifest" So I removed all my references to the google-place-services_lib and still received the error. I downloaded the 2.1.1 Robolectric code from github and started debugging through it. I found that org.robolectric.AndroidManifest class has a method called getLibraryManifests which calls createLibraryManifests and that calls findLibraries. One of the things it does is loads the project.properties file in your project. In my case my project.properties file at this content:
android.library.reference.1=../../../ADK/adt-bundle-windows-x86_64-20130522/sdk/extras/google/google_play_services/libproject/google-play-services_lib
This was created when I used the Android Tools for the google play services install per Google's documentation. If you comment out that line from project.properties file then the error goes away. A better solution is to leave it and then create your own file called test-project.properties and put in the correct directory for android.library.reference.1 and the AndroidManifest will override the original value.
Here is the relevant code from AndroidManifest.java
protected List<FsFile> findLibraries() {
FsFile baseDir = getBaseDir();
List<FsFile> libraryBaseDirs = new ArrayList<FsFile>();
Properties properties = getProperties(baseDir.join("project.properties"));
// get the project.properties overrides and apply them (if any)
Properties overrideProperties = getProperties(baseDir.join("test-project.properties"));
if (overrideProperties!=null) properties.putAll(overrideProperties);
if (properties != null) {
int libRef = 1;
String lib;
while ((lib = properties.getProperty("android.library.reference." + libRef)) != null) {
FsFile libraryBaseDir = baseDir.join(lib);
libraryBaseDirs.add(libraryBaseDir);
libRef++;
}
}
return libraryBaseDirs;
}

Could not find class XXX referenced from method XXX.<YYY>

I'm working on a libGDX project and I have a class called CheerVArachnids that has another inline class which is an event listener. When I run this project on the desktop it works fine. BUT when I run on my Android device, it can't find that inline class and I get the following error:
Could not find class 'com.bbj.cva.CheerVArachnids$PlaceUnitListener', referenced from method com.bbj.cva.CheerVArachnids.<init>
Here are the important parts of my class:
package com.bbj.cva;
public class CheerVArachnids implements ApplicationListener {
class PlaceUnitListener implements EventSubscriber<PlaceUnitEvent> {
#Override
public void onEvent(PlaceUnitEvent event)
{
//
}
}
public CheerVArachnids() {
EventBus.subscribe(PlaceUnitEvent.class, new PlaceUnitListener());
EventBus.subscribe(RemoveScreenObjectEvent.class,
new RemoveScreenObjectListener());
}
}
Any ideas why on Android, at runtime it can't find that inline class?
Since some ADT-Version you have to set which libraries / projects should be exported too.
Project-Propiertes -> Java Build Path -> Order and Export -> Check your Sources and other Libraries you are using.
Do these Export-Settings for your Core- and Android-Project.
Then it should work fine on Android.
In my case, everything worked fine until I installed the new updates for the SDK and Eclipse.
I got an error: "Could not find class..."
I found solution in another stackoverflow site.
I have a similar problem when using external jar (in my case openCSV). The reason I had a problem was due to a change in ADT 17 (or above). What I needed to do to resolve the problem was
In Eclipse go to Properties -> Java build path -> Order and export.
Mark my jar.
Move jar to top of the list.
The solution was found in the following page which reference to a very good article.
First you should: import XXX(Class).java,
If you added external library jar file import them to the LIB folder.
After that:
Right Click to your Project -> Properties -> Java Build Path -> Order and Export(tab) -> select All -> press OK -> Clean your Project.
Hope this solve this issue

Categories

Resources