android.os.Bundle cannot be resolved in libgdx Android project - java

I've just started using Libgdx to practice making games and I used the project creation .jar provided on the site to create the initial projects. However an error shows up in the Android project which says:
android.os.Bundle cannot be resolved.
I am using Eclipse for Java IDE. If I put the cursor over AndroidApplication which is underlined in red, it suggests that I configure the build path. I believe I have the Android SDK installed, because it worked a while back on a different workspace on a simple example project. Does anyone know what I might have done wrong in this new workspace? How can I configure the build path for the AndroidApplication class?
BTW, I believe I'm using Java 1.6 as that's what JAVA_HOME points to, although I've also got Java 1.7 installed. That might not be relevant though...
package com.example.drop;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class MainActivity extends AndroidApplication {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
cfg.useAccelerometer = false;
cfg.useCompass = false;
initialize(new Drop(), cfg);
}
}

The error you are seeing is related to the Android SDK configuration, and is not specific to libGDX. The compiler does not know which Android libraries to compile against.
Use the LibGDX tutorials to setup your projects correctly. (See
https://github.com/libgdx/libgdx/wiki/Manual-project-setup#android-project-setup.
The first step in there does the Android-specific setup.)
If you do not want to create a new project but fix an existing project, the following steps should configure a project to build against Android:
right-click on the project in the Eclipse Package Explorer
select Properties and pick the Android section
Make sure exactly one of the "Project Build Targets" is selected.
That should add the required Android libraries to the build path as a side-effect.

Please, also check to have ADT installed on Eclipse.

Related

ActivityMainBinding class does not recognize my package

I am trying to make a project using MVVM.
I've enabled dataBinding by modifying the gradle file.
dataBinding{
enabled = true
}
but after I build my project it doesn't recognize on of my packages.
I tried clean and restart android studio but it does not fix.
If you are trying to import a whole package you should use.
com.example.yourpackage.*
In this case the compiler can understand what you are doing.
If you have created Your viewModel Check the Following.
Have you mentioned Variable in your layout.
Check if you have missed typed any while binding.
clean and Rebuild Project
Goto Gradle->->app->other->dataBindingGenBaseClassesDebug and run it.
This worked for my project.
try this -
import com.example.mvvmLogin.ViewModel.LoginViewModel;`
and at the declaration -
protected LoginViewModel mViewMOdel;
do the same for other activities in the packages
if you are using
import com.example.mvvmLogin.ViewModel.*;
declaration is done by
protected LoginViewModel mViewMOdel;
using protected ViewModel.LoginViewModel mViewMOdel; is not correct

How do I begin to use this Java library?

Teaching myself Java, still very new. Last night I learned how to import this library into my project in Android Studio. But now I'm confused as to how to actually start using it.
I know that Java works with classes and that supposedly a library is just a collection of classes (and probably others things too...) that you can begin using once you import it. But the author of this library told me to just use this:
BackgroundMail bm = new BackgroundMail(context);
bm.setGmailUserName("sendername#gmail.com");
bm.setGmailPassword("sender_email_password");
bm.setMailTo("receiver#gmail.com");
bm.setFormSubject("Subject");
bm.setFormBody("Body");
bm.send();
But when I try to put that into another one of my classes, I get red errors all over the place. So then I tried to create a Java class within my app's files and I still got red errors. Could someone kindly help me, a total beginner, get started here? I'd like to use this library to send an email in the background of my app.
To import the library:
I followed this answer: https://stackoverflow.com/a/35369267/5241266 and used Approach 2.
MainActivity.Java: this is where I put the import code.
package moviehelper.moviesfree;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.creativityapps.gmailbackgroundlibrary.BackgroundMail;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
For now, I have not added the block of code that the author told me to use (see above).
The Gradle Console error:
I get the following error when doing Build -> Make Project:
error: package com.creativityapps.gmailbackgroundlibrary does not exist
import com.creativityapps.gmailbackgroundlibrary.BackgroundMail;
My project tree: I think there might be some problem with this structure. It looks like the library was added as its own project? Although I'm not sure.
If you don't want to use the JitPack approach as documented in the instructions, then look at the settings.gradle file in the Github example.
It includes both modules (app and the library).
Then, once that is setup, you can compile project(:libraryName) in the app/build.gradle file's dependencies section. Again, see the Github sample for the syntax.
With those two steps (plus one to download the library), it should be importable within the app code.
Assuming you followed along with the other steps on the readme, at the top of your code you need to tell the source file to import the classes:
import com.creativityapps.gmailbackgroundlibrary.BackgroundMail;
public class MainActivity extends AppCompatActivity {
[your code]
}
I would also recommend looking through the sample code included in the github project
You are doing some wrong steps friend. You can follow this
Find your gradle file with name buid.gradle (Project: [ YOUR_PROJECT_NAME ] )
Then find and add this line
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
You are done 50% now. Now press SHIFT+CTRL+ALT+S and wait for a window.
On the Window, select DEPENDENCY TAB on top.
Click on + BUTTON at top right. Click on Library Dependency.
Now paste com.github.yesidlazaro:GmailBackground:1.2.0 there.
Click on OK and exit the window. Gradle recompiles.
Now simply put your code, If RED syntax error showing, Click at the code where error is showing and when a BLUE pop comes, Press ALT+ENTER.
Everything done..!

How to use the generated .so library in another Android Project?

I’ve followed http://kn-gloryo.github.io/Build_NDK_AndroidStudio_detail/ and it works well! However, I want to use the generated .so library in a new Android application, and I simply don’t know how to do this... I’ve been struggling for days and if any step-by-step tutorial can be shared that would be helpful!
This is the Android Project MyApp which I used to generate the .so files:
MainActivity :
Java Class : MyNDK
header file: com_demo_ble_myapp_MyNDK.h
Cpp file: MyLibrary
And this is the structure of my new Android project useSOLib, I simply copy all the so files from MyApp\app\src\main\libs to useSoLib\app\src\main\jniLibs
And this is MainActivity in useSoLib:
I can Build-> Make Project successfully, but when I run it on the device, the app shows "Unfortunately, useSoLib has stopped." and crushed. I know I miss some steps here, but I'm new to Android Studio so I have no clue where I should start with... thank you in advance for any suggestions! :)
You should import MyNDK and use its instance. JNI library is related to Java class. Change the code:
public class MainActivity extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("MyTag", new MyNDK().getMyString());
}
}
You can either export the MyNDK class as a jar package or create an aar bundle. Then import the Java class into your new project with JNI library.
The post How to Build *.so Library Files into AAR Bundle in Android Studio may help you.

bugs in eclipse after installing LibGDX

i had no project in eclipse, and i just followed the steps in this toturial: https://www.youtube.com/watch?v=S9fs1PVTyUc&src_vid=6i78aqugqds&feature=iv&annotation_id=annotation_4141831685
and it opened for me a few projects named:
project,
project-android,
project-core,
project-desktop,
project-ios.
and the project-android had an error.
here is the code:
package com.ak01.projext.android;*
import android.os.Bundle;**
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.ak01.projext.Projec;
public class AndroidLauncher extends AndroidApplication {***
#Override
protected void onCreate (Bundle savedInstanceState) {****
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new
AndroidApplicationConfiguration();
initialize(new Project(), config);
}
}
but it has a few errors although i didn't touch it yet(the number of *'s matches to the line)
*The type android.os.Handler cannot be resolved. It is indirectly referenced from required .class files
**The import android.os.Bundle cannot be resolved
***Multiple markers at this line
-The type android.app.Activity cannot be resolved. It is indirectly referenced from
required .class files
-The hierarchy of the type AndroidLauncher is inconsistent
****Bundle cannot be resolved to a type
It looks like you have not installed the Android developer tools.
To test this, right click your project and press build path. On the side there should be an 'Android' tab, if there isn't you need the android plugin for eclipse.
You can try to use the advanced option to check eclipse as #Tuss said in a comment. Also note that you need the version 19 of Android SDK (it isn't valid the last version at the time of writing this, API 23).
When creating the Libgdx project:
In Libgdx Project Generator open Advanced options.
Check Eclipse.
Generate your project.
In Eclipse:
Open Android SDK Manager: Window -> Android SDK Manager.
Mark if it isn't installed the SDK Plataform for Android 4.4.2 (API 19) and install it.
Finally import the projects with File -> Import -> General -> Existing Projects into Workspace.

Programs run fine with LibGDX -desktop but not LibGDX - Android?

So I have just set up Eclipse to work with LibGDX using Gradle. After I installed I noticed there was a problem with the Android package, there was a red cross next to the package. When I opened it further there was a red cross next to src then com.myname.game.android and then in AndroidLauncher.java. When I opened the AndroidLauncher.java, this was the code I got:
package com.faturbansloth.game.android;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.faturbansloth.game.MyGame;
public class AndroidLauncher extends AndroidApplication {
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new MyGame(), config);
}
}
When I looked at the errors in he code of AndroidLauncher.java they were saying:
-The type android.os.Handler cannot be resolved. It is indirectly referenced from
required .class files
-The import android.os.Bundle cannot be resolved
-Multiple markers at this line
- The type android.app.Activity cannot be resolved. It is indirectly referenced from
required .class files
- The hierarchy of the type AndroidLauncher is inconsistent
-Bundle cannot be resolved to a type
I am using SDK Manager 22.6.2 with the newest Gradle plugin for Eclipse. I have JRE 8 and JDK 7. Is there anyway to fix this problem? Thanks in advance.
There was no Android Version selected by default, so go:
Project -> Properties -> Android -> Project Build Target and select your preferred version
I have no idea why this works but it does for me. I installed the ADT plugin, refreshed the android section and the red cross disappeared.
Refer to the section under "Download the ADT Plugin" to install the ADT plugin.
http://developer.android.com/sdk/installing/installing-adt.html
After that, go to Eclipse > Package Explorer > Left click on Project-android > Select Refresh.

Categories

Resources