Reputation: 55
I am developing a 2d game in eclipse using Android, libgdx, app42api's and tiled maps. I am currently working on implementing a login system using app42api's user service. I successfully can register, and login to an account, from which i am working on loading my main play screen after logging in. After fixing a previous error, I was told to add in a few external jar's that app42api's services need to function properly. I added in the following jars: httpcore-4.1.jar, httpcore-1.1.1.jar, commons.logging-1.1.1, commons-logging-api-1.1.1. After originally adding in the jars, my app ran fine, logged in account and loaded the play screen. After messing around with what I had figured out, out of the blue I came across the following error, which now prevents me from running my android application at all.
Error: [2015-05-22 17:55:05 - wurfle-gdx-android] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class (org.apache.commons.logging.impl.WeakHashtable$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class. [2015-05-22 17:55:19 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/apache/commons/logging/Log; [2015-05-22 17:55:19 - wurfle-gdx-android] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/apache/commons/logging/Log;
I can run my app on desktop, but I have not initialized the app42api connection so desktop will not run the api. I have tried adding and removing the jars, cleaning my project and restarting my cp (some suggestions people said on other similar issues people have had relating to this problem), but nothing has worked.
I will attach some of my classes that are being used.
AndroidLauncher.java:
package com.wurfle.game.android;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.shephertz.app42.paas.sdk.android.App42API;
import com.wurfle.game.MainGameLoop;
import com.wurfle.game.network.App42Handler;
public class AndroidLauncher extends AndroidApplication
{
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
App42API.initialize(getContext(), App42Handler.apiKey, App42Handler.secretKey);
System.out.println("initialized app42api...");
initialize(new MainGameLoop(), config);
}
}
Login.java:
package com.wurfle.game.network;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.shephertz.app42.paas.sdk.android.App42Exception;
import com.shephertz.app42.paas.sdk.android.user.UserService;
import com.wurfle.game.States.Play;
public class Login implements Screen
{
private TextField usernameTxtField, passwordTxtField;
private TextButton loginBtn;
private Skin loginSkin;
private Stage stage;
private Table table;
private TextFieldStyle txtFieldStyle;
private TextureAtlas loginAtlas;
private BitmapFont font;
public static String username;
@Override
public void render(float delta)
{
Gdx.gl.glClearColor(1,1,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
}
@Override
public void show()
{
stage = new Stage();
// set input processor to stage element
Gdx.input.setInputProcessor(stage);
table = new Table();
table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
font = new BitmapFont();
txtFieldStyle = new TextFieldStyle();
txtFieldStyle.fontColor = Color.RED;
txtFieldStyle.font = font;
usernameTxtField = new TextField("", txtFieldStyle);
passwordTxtField = new TextField("", txtFieldStyle);
// set size of text fields
usernameTxtField.setSize(100, 25);
passwordTxtField.setSize(100, 25);
// register button
loginAtlas = new TextureAtlas("resmenu/menu/loginBtn.pack");
loginSkin = new Skin(loginAtlas);
// new style for exit btn
TextButtonStyle loginButtonStyle = new TextButtonStyle();
// when user clicks on button, load new image, when he lets go reload
// original image
loginButtonStyle.up = loginSkin.getDrawable("menuLoginBtn");
loginButtonStyle.down = loginSkin.getDrawable("menuLoginBtnPressed");
// off set btn
loginButtonStyle.pressedOffsetX = 1;
loginButtonStyle.pressedOffsetY = -1;
loginButtonStyle.font = font;
loginBtn = new TextButton("", loginButtonStyle);
// add new listener
loginBtn.addListener(new ClickListener()
{ // fire event
public void clicked(InputEvent event, float x, float y)
{
if(usernameTxtField.getText().equals("") || passwordTxtField.getText().equals(""))
{
System.out.println("need to input sumn..");
}
else
{
loginAccount(usernameTxtField.getText().trim(), passwordTxtField.getText().trim());
}
}
});
// add actors to table
table.center();
table.row();
table.add(usernameTxtField);
table.row();
table.add(passwordTxtField);
table.row();
table.add(loginBtn);
table.debug();
// add table to stage
stage.addActor(table);
}
public void loginAccount(String usr, String pw)
{
Login.username = usr;
try
{
UserService us = new UserService(App42Handler.apiKey, App42Handler.secretKey);
// if username & password exists
if(us.authenticate(usr, pw) != null)
{
System.out.println("account authenticated: " + usr + " just logged in");
((Game)Gdx.app.getApplicationListener()).setScreen(new Play());
dispose();
}
}
catch(App42Exception e)
{
e.printStackTrace();
}
}
@Override
public void resize(int width, int height)
{
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void dispose()
{
loginSkin.dispose();
loginAtlas.dispose();
font.dispose();
loginBtn.getListeners().clear();
stage.dispose();
}
}
I have ensured that my jars were properly added to the android build path as well. I have been trying to fix this for a while now, so any help is appreciated.
Thanks, Devon.
Upvotes: 0
Views: 177
Reputation: 81
After going with errors that you have shared I found some cases like:
Multiple dex files define Lorg/apache/commons/logging/Log; [2015-05-22 17:55:19 - wurfle-gdx-android] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/apache/commons/logging/Log;Two same library are added.
As you are using us.authenticate(usr, pw) network API on main UI Thread. I would like to suggest you to use our async API
UserService userService = App42API.buildUserService();
userService.authenticate(userName , pwd, new App42CallBack() {
public void onSuccess(Object response)
{
User user = (User)response;
System.out.println("userName is " + user.getUserName());
System.out.println("sessionId is " + user.getSessionId());
}
public void onException(Exception ex)
{
System.out.println("Exception Message : "+ex.getMessage());
}
});
Once you will get the response use runOnUIThread to update on UI Thread.
Please also share some logcat logs that will help us to track the exact problem.
Upvotes: 0