简体   繁体   English

将现有的android studio项目与libgdx项目合并

[英]Merge existing android studio project with libgdx project

I have created an app with android studio. 我已经使用android studio创建了一个应用。 I also created a game with libgdx. 我还用libgdx创建了一个游戏。 What I want is to be able to click a button on the app that I created and open my libgdx game. 我想要的是能够单击我创建的应用程序上的按钮并打开我的libgdx游戏。 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 . 对于更多的上下文,这是另一个类似的问题

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. 在您的libgdx项目中,打开清单文件并找到该单独活动的部分,然后将其复制到记事本或其他要挂在其上的文件。 It looks like this, but you might have named your activity differently. 看起来像这样,但是您可能对活动进行了不同的命名。 Also, remove the <intent-filter> block so it looks like this. 另外,删除<intent-filter>块,使其看起来像这样。

    <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. 将您的strings.xml文件重命名为libgdx_strings.xml之类的文件,并使用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. 现在,将所有代码文件(src,res和AndroidManifest.xml)从您的Android项目复制并粘贴到libgdx项目的android模块中,进行替换。

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. 如果您的libgdx项目的包名称与Android应用程序项目的包名称不同,则可能需要通过在类名称前面键入整个包名称来完全限定android:name字段的质量。

If your Android project had any libraries, also copy those. 如果您的Android项目有任何库,也请复制它们。 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. 如果在build.gradle文件中包含dependencies块,请将其中的行复制到libgdx项目的顶级build.gradle文件的android dependencies块中。

If there are any resource conflicts, you might see that R cannot be found in some of your classes. 如果存在任何资源冲突,您可能会看到在某些类中找不到R。 If that's the case, make sure none of your strings from libgdx_strings.xml have the same name as ones in strings.xml. 如果是这种情况,请确保libgdx_strings.xml中的所有字符串都没有与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)); 现在,您可以使用startActivity(new Intent(getBaseContext(), AndroidLauncher.class));来打开您的AndroidLauncher Activity,就像从应用程序的其他类中打开其他Activity一样startActivity(new Intent(getBaseContext(), AndroidLauncher.class)); , for example. , 例如。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM