Initial project error libgdx 1.0 - java

I have created a project using libgdx project generator, then I imported him to Eclipse. Then run on android emulator, but there is an error "libgdx requires OpenGL ES 2.0". I dont know what is the problem
public class AndroidLauncher extends AndroidApplication {
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new MyGdxGame(), config);
}
}
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
#Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
}
#Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mygdx.game.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="com.mygdx.game.android.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

LibGDX does not support anything < OpenGL ES 2.0 anymore, since version 1.0.
That's not a problem in most cases, because nowadays there are less than 0.1% of all devices which do not support OpenGL ES 2.0. See the statistics here.
In your case it is probably the fault of the emulator. You should not use that to test your games, since it is terribly slow and takes extremely long to start. Use a real device and run your app there, which will save you a lot of time and you will get more realistic results.
With LibGDX, you can even skip this step, since it is a cross platform framework, meaning that you can just run your game on your desktop PC for debugging and testing and only in the end test it on mobile devices.
If you really need OpenGL ES 1.1 support, you can use LibGDX version 0.9.9, which still supported it.

Related

App for setting up a certain series of alarms is only working in the Android Studio Emulator

My final goal is to easily activate and deactivate a certain series of 17 alarms in the clock app whenever necessary. Unfortunately, the app only offers the option to either deleting(!) all alarms at once or deactivating one by one. The same applies to every other app from the Play Store I have tried.
I think an acceptable workaround solution would be to delete all alarms with the mentioned functionality and re-implement the series of alarms programmatically as needed. So, I wrote a minimalist app in Android Studio that works perfectly fine in the emulator.
After building the debug APK, I transferred it on my smartphone and installed it without any errors. Now I am facing the problem that after starting my app only the first alarm is created. Does somebody have an explanation for this error. Thank you!
MainActivity.java
package com.example.setalarms;
import android.app.Activity;
import android.content.Intent;
import android.provider.AlarmClock;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Arrays;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] messages = {"alarm1","alarm2to16","alarm17"};
int[] hours = {7,8,9};
int[] minutes = {0,0,0};
ArrayList<Integer> days = new ArrayList<>(
Arrays.asList(1,2,3,4,5,6,7)
);
Intent[] intents = new Intent[messages.length];
for (int i = 0; i < messages.length; i++) {
Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM)
.putExtra(AlarmClock.EXTRA_MESSAGE, messages[i])
.putExtra(AlarmClock.EXTRA_HOUR, hours[i])
.putExtra(AlarmClock.EXTRA_MINUTES, minutes[i])
.putExtra(AlarmClock.EXTRA_DAYS, days)
.putExtra(AlarmClock.EXTRA_SKIP_UI, i != messages.length - 1);
intents[i] = intent;
}
startActivities(intents);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.SetAlarms"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
Hardware / Software
SAMSUNG Galaxy A3 (2017) SM-A320FL
Android Studio Dolphin 2021.3.1 Patch 1
Android 8.0.0 (Oreo)
Clock 7.0.92.7 (Galaxy Store)

Issues running any new android project - Default Activity Not found / Invalid Java package

total noob with lots of issues with Android Studio.
Default Activity error
Invalid java package name
Getting a Default Activity error on any app or new project I run - below is an example of the AndroidManifest.xml
"Error running 'app': Default Activity not found"
I have checked more than 100 times I am using the right package names and that my activity is declared in the android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.coleary.change;">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.example.coleary.change.MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="#string/TicTacToe"
android:theme="#style/AppTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The package name is the same in the java code:
package com.example.coleary.change;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
// use tictactoe code in our code for a new game
private TicTacToeGame mGame;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.example.coleary.change.R.layout.activity_main);
//this activity(game) is a context within a main activity
mGame= new TicTacToeGame(this);
}
}
When I run the project I get the following error also:
Package 'com.example.coleary.change;' from AndroidManifest.xml is not a valid Java package name as 'change;' is not a valid Java identifier.
I have changed the package name through Refactoring to 5 different names to no avail.
I have spent over 15 hours hours trying to troubleshoot these issues and because I have the same issue on multiple projects / packages and apps I am completely stuck - any help really appreciated!
Remove the semi-colon after change in your AndroidManifest. Package names can't contain semi-colons.

Android, no AppCompat, full screen - the most correct style?

Android app, strictly level 21 onwards only. Not using AppCompat.
Full-screen app with absolutely no bars.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.client.client">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Main"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Am confused between:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
versus...
android:theme="#android:style/Theme.DeviceDefault.NoActionBar.Fullscreen"
What is the best and most modern choice?
I don't understand the complete history of the difference between those and similar values in Android :/
Again, not using AppCompat, if that matters.
Here's a screenshot of how I want the app to look on all devices:
what is the best and most modern choice?
With a minSdkVersion of 21+, you can use themes based off of Theme.Material, such as Theme.Material.Light.NoActionBar.Fullscreen.
An answer for 2022:
I have found that the only way I can do it these days is:
// completely fullscreen:
protected void utterlyFullScreen() {
// go top the physical top (ie under the statusBars):
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
WindowInsetsControllerCompat windowInsetsController =
ViewCompat.getWindowInsetsController(getWindow().getDecorView());
if (windowInsetsController == null) { return; }
// hide the bars:
windowInsetsController.hide(WindowInsetsCompat.Type.navigationBars());
// statusBars top one. navigationBars bottom one. systemBars both.
// handle reveal:
windowInsetsController.setSystemBarsBehavior(
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
// also:
// windowInsetsController.setAppearanceLightNavigationBars(true);
// or, do that in theme
}
I call that in every activity onCreate, after super, but before setting the view.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
utterlyFullScreen();
setContentView(R.layout.activity_main);
I am minSdk 24 as of writing.

Why i only got a Blank map with Google Maps Android API V2?

i'm trying to build a app with a Google Maps Api V2, but i only got a blank screen with zoom buttons everytime. I think everything is fine in my code. I have all the permissions necessary, i correctly got the Key. I already delete debug.keystore to eclipse generate another one, but i still got the same blank screen with zoom buttons. Can anyone see if i doing something wrong in my codes ?
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.meu"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<permission
android:name="com.example.meu.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.meu.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="****My key here***" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
My layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
My Java code:
package com.example.meu;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity {
// Google Map
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
// Loading map
setContentView(R.layout.activity_main);
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
I already read a lot of things here, but no one could help me.
Firstly: As your map is a fragment (MAPS API V.2) you should extend your MainActivity as a FragmentActivity
public class MainActivity extends FragmentActivity {
instead of
public class MainActivity extends Activity {
Secondly: When casting the fragment as a map use the SupportMapFragment class (for better cmpatability between android versions) and getSupportFragmentManager() to find your map fragment.
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
instead of
((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
Also: as per the comments of the question "asker"(!?): If you find that your app is working in an Emulator but not on an actual device, ensure that you use your Debug.Keystore when building the App.
Note: Ensure at all times that you are using backwards compatible support libraries across your entire app (If you are targeting multiple versions of android of course but I can't understand why anyone would limit their app to only a couple of versions?) and also that all your keys, credentials, Auths etc.. are properly set up in the Google developers console. https://console.developers.google.com/
After do what Ryno Coetzee suggest me, the app work on emulator but not on device. But the app doesnt work on device because when i export to a apk file, i was using another keystore instead debug.keystore. After that, my app finally work on device and on emulator.
Thanks !

Failed to install Map.apk on device 'emulator-5554'

I'm new to the Android world, and I need to create an app using Google Maps Android API. I follow the instructions in:
https://developers.google.com/maps/documentation/android/start
and whenever I start the AVD I get an error:
[2013-12-05 21:04:37 - Map] Failed to install Map.apk on device 'emulator-5554!
[2013-12-05 21:04:37 - Map] (null)
[2013-12-05 21:04:38 - Map] Launch canceled!
My MainActivity code:
package com.example.map;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
my MainActivity XML file:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
and my Manifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.xxxxxxxxxHIDDENxxxxxxxx"
android:value="xxxxxxxxxHIDDENxxxxxxxx"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.map.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Also tried the code that it's provided here:
https://developers.google.com/maps/documentation/android/
being the MainActivity file code:
package com.example.map;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_activity);
// Get a handle to the Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
LatLng sydney = new LatLng(-33.867, 151.206);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
map.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("The most populous city in Australia.")
.position(sydney));
}
}
Any Ideas?
The first thing I would recommend is to not show your API key to the public; this are supposed to be private to whomever is developing the application.
Also the format of this meta tag is wrong:
<meta-data
android:name="com.google.android.maps.v2.AIzaSyB7AMKbYsVajgb6D0zpq9wUODX9gdR2DhE"
android:value="AIzaSyB7AMKbYsVajgb6D0zpq9wUODX9gdR2DhE"/>
You are copying your API key at the end of the name. I strongly suggest you create a new API key and do not use this one that you have exposed to the public. There might be other errors, but without the stack trace is hard to say.
See this page: http://developer.android.com/google/play-services/setup.html
Specifically:
To test your app when using the Google Play services SDK, you must use
either:
A compatible Android device that runs Android 2.3 or higher and includes Google Play Store.
The Android emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or higher.
So make sure the emulator you're using is Android 4.2.2 or greater. If it is below this level, Google Play Services is not available on the emulator, and you must use a physical android device to test it out.
If you have to test on a lower-end device emulator, there are workarounds to this but they aren't officially supported by Google so your mileage may vary.
See this link:
Custom emulator that supports Google Maps API

Categories