简体   繁体   English

无法将AndEngine添加到Android Studio

[英]Unable to add AndEngine to Android Studio

I am trying to almost 2 days to add AndEngine to Android Studio but unable to do so. 我试图将AndEngine添加到Android Studio差不多2天但无法这样做。 I tried the following two methods, neither worked. 我尝试了以下两种方法,但都没有奏效。

1st Try I download the AndEngine code from GitHub Link -- this is NOT a Gradle Project 第一次尝试我从GitHub链接下载AndEngine代码 - 这不是Gradle项目

and tried to add it to my Android Studio build.gradle and settings.gradle, but i get this error, my screenshot: https://postimg.cc/image/5mcvpvsar/ (I think I am getting this error because AndEngine is not a gradle project - HOW TO MAKE IT A GRADLE PROJECT??) 并尝试将其添加到我的Android Studio build.gradle和settings.gradle,但我得到此错误,我的屏幕截图: https ://postimg.cc/image/5mcvpvsar/(我想我收到此错误,因为AndEngine不是一个gradle项目 - 如何使它成为一个重点项目??)

2nd Try I have also tried adding the andengine.jar (file I just googled for) in /libs folder and do right-click --> "Add as Library" but still I cannot do "import org.andengine...." in my project files. 第二次尝试我也尝试在/ libs文件夹中添加andengine.jar(我刚刚用google搜索的文件)并右键单击 - >“添加为库”但仍然无法执行“import org.andengine ....”在我的项目文件中。

All tutorials available online are in Eclipse, I am using Android Studio. 在线提供的所有教程都在Eclipse中,我使用的是Android Studio。

I am not even able to start. 我甚至无法开始。

UPDATE : Yes, I gave up using Android Studio for AndEngine! 更新 :是的,我放弃了使用Android Studio for AndEngine! Took me 15mins to do this in Eclipse, compared to the unsuccessful weekend (which i will never get back!) I spent on Android Studio 花了15分钟在Eclipse中做到这一点,相比之下不成功的周末(我永远不会回来!)我花在Android Studio上

I use this techique: I set this in my settings.gradle 我使用这个技术:我在settings.gradle设置了这个

include 'andengine'

project(':andengine').projectDir = new File(settingsDir, '../relative/path/to/andengine')

that is in the root directory of the project (I think gradle has already created it for your main project). 这是在项目的根目录中(我认为gradle已经为您的主项目创建了它)。

In AndEngine use a build.gradle like the following for the AndEngine project 在AndEngine使用build.gradle像为AndEngine项目如下

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}

apply plugin: 'android-library'

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}

and add in the dependencies of your project 并添加项目的依赖项

compile project(':andengine')

Maybe you have to close and reopen Android Studio, but normally for me this works. 也许你必须关闭并重新打开Android Studio,但通常对我来说这很有用。

BTW after have write the answer I see that someone has opened a pull request for a gradle build file. BTW在写完答案之后我看到有人打开了一个gradle构建文件的pull请求

I created a tutorial for this - How to add Andengine, Andengine Tile Map, Andengine PhysicsBox2D to Android Studio 0.8.9. 我为此创建了一个教程 - 如何将Andengine,Andengine Tile Map,Andengine PhysicsBox2D添加到Android Studio 0.8.9。

Here is the link, I hope everything works - https://docs.google.com/document/d/1zk2QjNiPvkj52G4qSVivEPrLfkCUVqmnCVH8TfsnER8/edit 这是链接,我希望一切正常 - https://docs.google.com/document/d/1zk2QjNiPvkj52G4qSVivEPrLfkCUVqmnCVH8TfsnER8/edit

ANDENGINE WITH ANDROID STUDIO 0.8.9 ANDENGINE WITH ANDROID STUDIO 0.8.9

Note: I am using the AnchorCenter brach and TortoiseGit to get all the files. 注意:我使用AnchorCenter brach和TortoiseGit来获取所有文件。

  1. Download Andengine from github using TortoiseGit: https://github.com/nicolasgramlich/AndEngine 使用TortoiseGit从github下载Andengine: https//github.com/nicolasgramlich/AndEngine
  2. After the dowload use TortoiseGit to switch to branch GLES2-AnchorCenter 下载后使用TortoiseGit切换到分支GLES2-AnchorCenter
  3. Create new project in Android Studio 在Android Studio中创建新项目
  4. Create new module: 创建新模块:
  5. Select File -> New Module -> Android Library 选择文件 - >新模块 - > Android库
  6. Set Application name to AndEngine 将应用程序名称设置为AndEngine
  7. Set Module Name to AndEngine 将模块名称设置为AndEngine
  8. Set Package Name to org.andengine 将包名称设置为org.andengine
  9. Set Minimum SDK 14 设置最低SDK 14
  10. Target SDK 19 目标SDK 19
  11. Compile with 19 编译19
  12. Theme None 主题无
  13. Keep clicking next until module is created (no difference what you pick) 继续点击下一步,直到创建模块(没有区别你选择的)
  14. Enter the folder where you have downloaded Andengine, enter src/org/andengine and copy all the files inside. 输入已下载Andengine的文件夹,输入src / org / andengine并复制其中的所有文件。
  15. Paste the copied files into your new module in your project src/java/org.andengine. 将复制的文件粘贴到项目src / java / org.andengine中的新模块中。 After pasting everything remove tha MainActivity that was created on default 粘贴后,删除默认情况下创建的MainActivity
  16. Enter the folder where you have downloaded Andengine, copy AndroidManifest and paste it into your new module (src/main) 输入已下载Andengine的文件夹,复制AndroidManifest并将其粘贴到新模块(src / main)
  17. Add the module to the project: 将模块添加到项目中:
  18. Select File-> Project Structure -> app-> Dependencies 选择文件 - >项目结构 - > app-> Dependencies
  19. Click the “+” button and pick “Module Dependency” 单击“+”按钮并选择“模块依赖关系”
  20. Select from the list your AndEngine Module 从列表中选择您的AndEngine模块
  21. Check your project gradle in app folder (build.gradle) and make sure you have a line like this under dependencies - compile project(':AndEngine') 在app文件夹(build.gradle)中检查项目gradle并确保在依赖项下有这样的行 - compile project(':AndEngine')

You should now be able to use AndEngine in your project 您现在应该能够在项目中使用AndEngine

ANDENGINE TMX TILED MAP EXTENSION WITH ANDROID STUDIO 0.8.9 ANDENGINE TMX TILED MAP EXTENSION with ANDROID STUDIO 0.8.9

Note: We do this the same way like with Andengine but we change a few things: 注意:我们以与Andengine相同的方式执行此操作,但我们更改了一些内容:

  1. Download AndengineTMX from github using TortoiseGit: https://github.com/nicolasgramlich/AndEngineTMXTiledMapExtension 使用TortoiseGit从github下载AndengineTMX: https//github.com/nicolasgramlich/AndEngineTMXTiledMapExtension
  2. After the dowload use TortoiseGit to switch to branch GLES2-AnchorCenter 下载后使用TortoiseGit切换到分支GLES2-AnchorCenter
  3. Create new project in Android Studio 在Android Studio中创建新项目
  4. Create new module: 创建新模块:
  5. Select File -> New Module -> Android Library 选择文件 - >新模块 - > Android库
  6. Set Application name to AndEngineTMXTiledMapExtension 将应用程序名称设置为AndEngineTMXTiledMapExtension
  7. Set Module Name to AndEngineTMXTiledMapExtension 将模块名称设置为AndEngineTMXTiledMapExtension
  8. Set Package Name to org.andengine.extension.tmx 将包名称设置为org.andengine.extension.tmx
  9. Set Minimum SDK 14 设置最低SDK 14
  10. Target SDK 19 目标SDK 19
  11. Compile with 19 编译19
  12. Theme None 主题无
  13. Keep clicking next until module is created (no difference what you pick) 继续点击下一步,直到创建模块(没有区别你选择的)
  14. Enter the folder where you have downloaded AndengineTMX , enter src/org/andengine/extension/tmx and copy all the files inside. 输入已下载AndengineTMX的文件夹,输入src / org / andengine / extension / tmx并复制其中的所有文件。
  15. Paste the copied files into your new module in your project src/java/org.andengine.extension.tmx. 将复制的文件粘贴到项目src / java / org.andengine.extension.tmx中的新模块中。 After pasting everything remove tha MainActivity that was created on default 粘贴后,删除默认情况下创建的MainActivity
  16. Enter the folder where you have downloaded AndengineTMX, copy AndroidManifest and paste it into your new module (src/main) 输入已下载AndengineTMX的文件夹,复制AndroidManifest并将其粘贴到新模块(src / main)
  17. Add the module to the project: 将模块添加到项目中:
  18. Select File-> Project Structure -> app-> Dependencies 选择文件 - >项目结构 - > app-> Dependencies
  19. Click the “+” button and pick “Module Dependency” 单击“+”按钮并选择“模块依赖关系”
  20. Select from the list your AndengineTMX Module 从列表中选择您的AndengineTMX模块
  21. Check your project gradle in app folder (build.gradle) and make sure you have a line like this under dependencies - compile project(':AndEngineTMXTiledMapExtension') 在app文件夹(build.gradle)中检查项目gradle并确保在依赖项下有这样的行 - compile project(':AndEngineTMXTiledMapExtension')

You should now be able to use AndEngineTMXTiledMapExtension in your project. 您现在应该能够在项目中使用AndEngineTMXTiledMapExtension。

ANDENGINE PHYSICSBOX2D WITH ANDROID STUDIO 0.8.9 ANDENGINE PHYSICSBOX2D与ANDROID STUDIO 0.8.9

  1. Download this file - http://dh.st/FyC 下载此文件 - http://dh.st/FyC
  2. Unzip the file 解压缩文件
  3. You should have 2 jar files, copy them to your project app/libs 你应该有2个jar文件,将它们复制到你的项目app / libs
  4. Right click on andenginephysicsbox2dextension.jar and select “Add as library” (or something like this) 右键单击andenginephysicsbox2dextension.jar并选择“Add as library”(或类似的东西)
  5. Open your build.gradle in your app folder 在app文件夹中打开build.gradle
  6. Under dependencies add compile files('lib/physicsbox2d_so_files.jar') 在依赖项下添加编译文件('lib / physicsbox2d_so_files.jar')

You should now be able to use PhysicsBox2D in your project. 您现在应该能够在项目中使用PhysicsBox2D。

Check out this tutorial on how to use andengine in android studio 查看本教程,了解如何在android studio中使用andengine

http://javaprogrammernotes.blogspot.in/2014/05/settings-up-andengine-in-android-studio.html http://javaprogrammernotes.blogspot.in/2014/05/settings-up-andengine-in-android-studio.html

Brief Summary of the Tutorial(Check out the full tutorial if you face any issue): 教程简介(如果您遇到任何问题,请查看完整教程):

Let's assume that you already have created a project and it has default structure. 假设您已经创建了一个项目并且它具有默认结构。 First create folder named third_party in the root directory of the project. 首先在项目的根目录中创建名为third_party的文件夹。 Then in third_party directory create subdirectories called andengine and andenginebox2d. 然后在third_party目录中创建名为andengine和andenginebox2d的子目录。 I assume that you already downloaded or cloned AndEngine and Box2d extension for it. 我假设你已经为它下载或克隆了AndEngine和Box2d扩展。 Put AndEngine and AndEngineBox2d in andengine and andenginebox2d directories respectively. 将AndEngine和AndEngineBox2d分别放在andengine和andenginebox2d目录中。 Create file named build.gradle in andengine directory and andenginebox2d directory. 在andengine目录和andenginebox2d目录中创建名为build.gradle的文件。 Build.gradle files is a file that tells gradle how to build your project. Build.gradle文件是一个告诉gradle如何构建项目的文件。

apply plugin: 'android-library'

android {
compileSdkVersion 17
buildToolsVersion "19.0.3"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 19
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-project.txt')
    }
}

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }

    instrumentTest.setRoot('tests')
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

Open settings.gradle that is located in your project's root directory and add two lines to it: 打开位于项目根目录中的settings.gradle,并为其添加两行:

include ':third_party:andengine'
include ':third_party:andenginebox2d'

Next open build.gradle which locates in app directory and add 接下来打开build.gradle,它位于app目录中并添加

compile project(':third_party:andengine')

The final step is to open AndroidManifest.xml in andegine and andenginebox2d directories and make them look like this: 最后一步是在andegine和andenginebox2d目录中打开AndroidManifest.xml,使它们看起来像这样:

<!--?xml version="1.0" encoding="utf-8"?-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.andengine">

<application>
</application>
</manifest>

application block is needed because of bug in manifest merging tool. 由于清单合并工具中的错误,需要应用程序块。 That's it! 而已! Now clean your project and press run. 现在清理项目并按下运行。 Everything should work just fine. 一切都应该工作得很好。

As the question's answers havn't been accepted yet, and I know people are still searching for solutions to this, I found this great website with very very clear and concise instructions to import AndEngine to your Android Studio projects. 由于这个问题的答案尚未被接受,而且我知道人们仍在寻找解决方案,我发现这个很棒的网站有非常清晰简洁的指示,可以将AndEngine导入到您的Android Studio项目中。 Here's the link: 这是链接:

http://geq-i.blogspot.com/2014/02/how-to-setup-andengine-in-android-studio.html http://geq-i.blogspot.com/2014/02/how-to-setup-andengine-in-android-studio.html

All credits go to the user who created this page. 所有积分将转到创建此页面的用户。 I can attest to the fact that this is working perfectly. 我可以证明这是完美的。 I JUST used this website after trying 10s of different ways. 在尝试了10种不同的方法后,我只是使用了这个网站。 Only thing to note on the link is the last part: 关于链接的唯一注意事项是最后一部分:

$ cd <project folder>/AndEngine/src/main
$ rm -r java/org
$ mv org java

This part is copying the org folder from . 这部分是从中复制org文件夹. to ./main/java . ./main/java Best way to do this is to just drag and drop the org folder into main/java when the project has finished building once. 最好的方法是在项目完成构建一次后将org文件夹拖放到main / java中。

Hope this helps! 希望这可以帮助!

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

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