nzn
nzn

Reputation: 11

Merge existing android studio project with libgdx project

I have created an app with android studio. I also created a game with libgdx. What I want is to be able to click a button on the app that I created and open my libgdx game. I've been searching for days, trying different methods but I just can't get it to work.

For more context here is another similar question.

Upvotes: 1

Views: 1100

Answers (1)

Tenfour04
Tenfour04

Reputation: 93591

In your libgdx project, open the manifest file and find the section for the lone activity and copy it to Notepad or something to hang on to it. It looks like this, but you might have named your activity differently. Also, remove the <intent-filter> block so it looks like this.

    <activity
        android:name=".AndroidLauncher"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation">
    </activity>

Rename your strings.xml file to something like libgdx_strings.xml and do the same with styles.xml.

Now copy and paste all your code files (src, res, and AndroidManifest.xml) from your Android project into the android module of your libgdx project, replacing.

Paste the above code back into your manifest. Also, you need to straighten out your package names if they are different. If your libgdx project had a different package name than your Android app project, you might need to fully quality the android:name field by typing the entire package name in front of the class name.

If your Android project had any libraries, also copy those. If it had a dependencies block in its build.gradle file, copy the lines within the block into the android dependencies block in the top level build.gradle file of your libgdx project.

If there are any resource conflicts, you might see that R cannot be found in some of your classes. If that's the case, make sure none of your strings from libgdx_strings.xml have the same name as ones in strings.xml. And so on for other resource files.

Now you can open your AndroidLauncher Activity just like any other Activity from your app's other classes using startActivity(new Intent(getBaseContext(), AndroidLauncher.class));, for example.

Upvotes: 1

Related Questions