[英]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来获取所有文件。
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相同的方式执行此操作,但我们更改了一些内容:
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
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! 希望这可以帮助!
Well i had the same problem - This helped me to solve it. 我有同样的问题 - 这有助于我解决它。 http://www.makethegame.net/android-andengine/how-to-setup-andengine-with-android-studio/
http://www.makethegame.net/android-andengine/how-to-setup-andengine-with-android-studio/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.