0

Любительски кодю на андроид студио с движком LibGDX. Все было хорошо, пока в один день я не попробовал построить апк и не получил ошибку несовместимости build gradle, после чего я ребилднул проект и вся прога перестала работать. При запуске пишется "Unfortunatly название приложения has stopped."Прикладываю код, может ошибка и в нем, но я склоняюсь к ошибке в грэдле. Помогите разобраться.

package com.hobogames.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;

import sun.applet.Main;


public class Lobby extends ApplicationAdapter {



    SpriteBatch batch;
    Texture backgroundimg;
    Texture start_buttonimg;
    Texture lobby_text1;
    Texture lobby_text2;
    Texture settingsimg;
    Texture square4menuimg;
    Texture back_buttonimg;
    Texture square4volumeimg;
    Texture volume_upimg;
    Texture volume_offimg;
    Texture list1_questionimg;
    Texture list1_aswer1img;
    Texture list1_answer2img;
    Texture list1_answer3img;

    Vector3 touchPos;

    Rectangle settings;
    Rectangle square4menu;
    Rectangle start_button;
    Rectangle list1_question;
    Rectangle list1_answer1;
    Rectangle list1_answer2;
    Rectangle list1_answer3;

    FreeTypeFontGenerator generator;

    Music lobby_theme;
    Music game_theme;
    Sound on_clicked;

    public boolean inlobby = true;
    public boolean green_theme = true;
    OrthographicCamera camera;
    boolean getting_smaller = false;
    public boolean getting_bigger = true;
    public boolean settings_opened = false;
    public boolean game_process = false;
    public boolean perehod = false;
    public int volumr_up = 0;
    public int list = 0;

    private BitmapFont backfont;
    private BitmapFont backfont2;



    @Override
    public void create ()  {


        backfont = new BitmapFont(Gdx.files.internal("newarial128.fnt"));
        backfont.getData().setScale(0.35f);
        touchPos = new Vector3();


        batch = new SpriteBatch();

        backgroundimg = new Texture("background.png");
        start_buttonimg = new Texture("start_button.png");
        lobby_text1 = new Texture("lobby_text1.png");
        lobby_text2 = new Texture ("lobby_text2.png");
        settingsimg = new Texture("settings.png");
        square4menuimg = new Texture("square4menu2.png");
        back_buttonimg = new Texture("back_button.png");
        square4volumeimg = new Texture("square4volume.png");
        volume_offimg = new Texture("volume_off.png");
        volume_upimg = new Texture("volume_up.png");
        list1_questionimg = new Texture("list1_question.png");
        list1_aswer1img = new Texture ("list1_answer1.png");
        list1_answer2img = new Texture("list1_answer2.png");
        list1_answer3img = new Texture("list1_answer3.png");

        lobby_theme = Gdx.audio.newMusic(Gdx.files.internal("lobby_theme.mp3"));
        game_theme = Gdx.audio.newMusic(Gdx.files.internal("game_theme.mp3"));
        on_clicked = Gdx.audio.newSound(Gdx.files.internal("on_clicked2 (online-audio-converter.com).mp3"));
        lobby_theme.setLooping(true);
        game_theme.setLooping(true);

        lobby_theme.setVolume(0.5f);
        game_theme.setVolume(0.75f);

        if (inlobby){lobby_theme.play();}


        start_button = new Rectangle();
        square4menu = new Rectangle();
        settings = new Rectangle();
        list1_question = new Rectangle();
        list1_answer1 = new Rectangle();
        list1_answer2 = new Rectangle();
        list1_answer3 = new Rectangle();


        square4menu.width = 660;
        square4menu.height = 720-150;
        square4menu.x = 720/2 - square4menu.width/2;
        square4menu.y = 1280/2 - square4menu.height/2 - 200;

        settings.width = 125;
        settings.height = 125;
        settings.x = 720 - settings.width - 15;
        settings.y = 0 + 15;

        start_button.width = 325;
        start_button.height = 325;
        start_button.x = 720/2 - start_button.width/2;
        start_button.y = 1280/2-300 + 50 - start_button.height/2;


        list1_question.height = 200;
        list1_question.width = 600;
        list1_question.x = 20;
        list1_question.y = 1280 - list1_question.height - 40;

        list1_answer1. height = 200;
        list1_answer1.width = 600 ;
        list1_answer1.x =720- list1_answer1.width  - 20 ;
        list1_answer1.y =1280 - 2*list1_question.height - 250;

        list1_answer2.height = 200;
        list1_answer2.width = 600;
        list1_answer2.x = list1_answer1.x;
        list1_answer2.y = list1_answer1.y - list1_answer2.height - 40;

        list1_answer3.height = 200;
        list1_answer3.width = 600;
        list1_answer3.x = list1_answer2.x;
        list1_answer3.y = list1_answer2.y - list1_answer3.height - 40;

        camera = new OrthographicCamera();
        camera.setToOrtho(false, 720, 1280);




    }

    private void perehod_from_list1 () {

        list1_answer1.x += 500* Gdx.graphics.getDeltaTime();
        list1_answer3.x += 500* Gdx.graphics.getDeltaTime();
        list1_question.x -= 500*Gdx.graphics.getDeltaTime();
        list1_answer2.x -= 500*Gdx.graphics.getDeltaTime();

    }

    private void getting_bigger () {

        if (getting_bigger) {
            start_button.width += 100 * Gdx.graphics.getDeltaTime();
            start_button.height += 100 * Gdx.graphics.getDeltaTime();
            if (start_button.height > 500){getting_bigger = false; getting_smaller = true;}
            }

    }
    private void getting_smaller () {
        if (getting_smaller) {
        start_button.width -= 100 * Gdx.graphics.getDeltaTime();
        start_button.height -= 100 * Gdx.graphics.getDeltaTime();
        if (start_button.height < 350) {getting_smaller = false;   getting_bigger = true;}
    }
    }
    public static void waiting (int n){
        long t0, t1;
        t0 = System.currentTimeMillis();
        do{
            t1 = System.currentTimeMillis();
        }
        while (t1 - t0 < n);
    }

    private void start_button_animation() {

        if (getting_bigger){getting_bigger();}

        if (getting_smaller){getting_smaller();}

            }



    @Override
    public void render () {

        Gdx.gl.glClearColor(0, 1, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        camera.update();


        batch.setProjectionMatrix(camera.combined);

        batch.begin();


        batch.draw(backgroundimg, 0, 0);
        if (inlobby){batch.draw(start_buttonimg, start_button.x, start_button.y, start_button.width, start_button.height);
        batch.draw(lobby_text1, 720/2 - 700/2 , 1280-200 - 250/2, 700, 250 );
        batch.draw(lobby_text2, 720/2 - 700/2 + 50 , 1280-250 - 250/2*2, 700-250, 250 );}



        if (game_process){

            if (list == 1) {
                batch.draw(list1_questionimg, list1_question.x, list1_question.y, list1_question.width, list1_question.height);
                batch.draw(list1_aswer1img, list1_answer1.x, list1_answer1.y, list1_answer1.width, list1_answer1.height);
                batch.draw(list1_answer2img, list1_answer2.x, list1_answer2.y, list1_answer2.width, list1_answer2.height);
                batch.draw(list1_answer3img, list1_answer3.x, list1_answer3.y, list1_answer3.width, list1_answer3.height);

            }

        }





        if (volumr_up % 2 == 0) {
            batch.draw(volume_upimg, settings.x, settings.y, settings.width, settings.height);
            if (inlobby){lobby_theme.play();}; if (game_process) {game_theme.play();}
        }
        if (volumr_up % 2 == 1) {
            batch.draw(volume_offimg, settings.x, settings.y, settings.width, settings.height);
            lobby_theme.pause(); if (game_process) {game_theme.pause();}
        }

        if (game_process) {lobby_theme.pause();}

        batch.end();

        if (perehod) {perehod_from_list1();}
        start_button.x = 720/2 - start_button.width/2;
        start_button.y = 1280/2-300 + 50 - start_button.height/2;

        if (Gdx.input.justTouched()) {
            touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
            camera.unproject(touchPos);
            if ((touchPos.x > settings.x) & (touchPos.y < settings.height) ) {
                volumr_up++; }

            if ( (touchPos.x > start_button.x) & (touchPos.x < start_button.x+start_button.width) &
                    (touchPos.y > start_button.y) & (touchPos.y < start_button.y + start_button.height)){

                inlobby = false;
                game_process = true;
                list = 1;

                }
                if (game_process) {



                if (Gdx.input.justTouched()) {
                        if ( (touchPos.x > list1_answer1.x) & (touchPos.x < list1_answer1.x + list1_answer1.width)
                        & (touchPos.y > list1_answer1.y) & (touchPos.y < list1_answer1.y + list1_answer1.height) )
                {if (volumr_up % 2 == 0)on_clicked.play(); perehod = true;}
                    if ( (touchPos.x > list1_answer2.x) & (touchPos.x < list1_answer2.x + list1_answer2.width)
                            & (touchPos.y > list1_answer2.y) & (touchPos.y < list1_answer2.y + list1_answer2.height) )
                    {if (volumr_up % 2 == 0)on_clicked.play();perehod = true;}
                    if ( (touchPos.x > list1_answer3.x) & (touchPos.x < list1_answer3.x + list1_answer3.width)
                            & (touchPos.y > list1_answer3.y) & (touchPos.y < list1_answer3.y + list1_answer3.height) )
                    {if (volumr_up % 2 == 0)on_clicked.play();perehod = true;}
                    }







                }

        }


        if (inlobby){start_button_animation();}




    }



    @Override
    public void dispose () {
        batch.dispose();
        backgroundimg.dispose();
        start_buttonimg.dispose();
        lobby_theme.dispose();
        game_theme.dispose();

    }
}
1
  • 4
    Вам стоит приложить ЛОГ, так же код из build.gradle
    – Turalllb
    27 дек 2017 в 0:10

1 ответ 1

1

Полагаю Вы обновили версию Gradle до 4-ки, но библиотека LIBGDX не совместима с этой версией, поэтому происходит эта ошибка.

Попробуйте в конфигурационных файлах Gradle понизить версию до: 'com.android.tools.build:gradle:2.2.0', либо до 3.0.1.

А так же указать дистрибутив не 4-ой версии, а ниже: distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip
Надеюсь Вам это поможет.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.