简体   繁体   English

如何为Android应用程序设置IntelliJ IDEA?

[英]How do I set up IntelliJ IDEA for Android applications?

如何为Android应用程序设置IntelliJ IDEA?

I've spent a day on trying to put all the pieces together, been in hundreds of sites and tutorials, but they all skip trivial steps. 我花了整整一天的时间尝试将所有内容组合在一起,涉及数百个站点和教程,但是它们都跳过了琐碎的步骤。

So here's the full guide: 因此,这里是完整的指南:

  1. Download and install Java JDK ( Choose the Java platform ) 下载并安装Java JDK选择Java平台
  2. Download and install Android SDK ( Installer is recommended ) 下载并安装Android SDK建议安装程序
  3. After android SD finishes installing, open SDK Manager under Android SDK Tools (sometimes needs to be opened under admin's privileges) android SD完成安装后,在Android SDK Tools下打开SDK Manager (有时需要在管理员权限下打开)
  4. Choose everything and mark Accept All and install. 选择所有内容并标记“ 全部接受”并安装。
  5. Download and install IntelliJ IDEA ( The community edition is free ) 下载并安装IntelliJ IDEA社区版是免费的
  6. Wait for all downloads and installations and stuff to finish. 等待所有下载和安装以及所有内容完成。

New Project: 新项目:

  1. Run IntelliJ 运行IntelliJ
  2. Create a new project (there's a tutorial here ) 创建一个新项目(这里有一个教程
  3. Enter the name, choose Android type. 输入名称,选择Android类型。
  4. There's a step missing in the tutorial, when you are asked to choose the JDK (before choosing the SDK) you need to choose the Java JDK you've installed earlier. 本教程中缺少一个步骤,当系统要求您选择JDK (在选择SDK之前)时,您需要选择之前安装的Java JDK Should be under C:\\Program Files\\Java\\jdk{version} 应该在C:\\Program Files\\Java\\jdk{version}
  5. Choose a New platform ( if there's not one selected ) , the SDK platform is the android platform at C:\\Program Files\\Android\\android-sdk-windows . 选择一个新平台(如果未选择),则SDK平台是位于C:\\Program Files\\Android\\android-sdk-windows的android平台。
  6. Choose the android version. 选择Android版本。
  7. Now you can write your program. 现在您可以编写程序了。

Compiling: 编译:

  1. Near the Run button you need to select the drop-down-list, choose Edit Configurations 在“ 运行”按钮附近,您需要选择下拉列表,然后选择“ 编辑配置”。
  2. In the Prefer Android Virtual device select the ... button 首选Android虚拟设备中,选择...按钮
  3. Click on create, give it a name, press OK. 单击创建,为其命名,然后按确定。
  4. Double click the new device to choose it. 双击新设备以将其选中。
  5. Press OK. 按确定。
  6. You're ready to run the program. 您已经准备好运行该程序。

The 5th step in "New Project' has apparently changed slightly since. 从那以后,“新项目”中的第五步显然有所变化。

Where it says android sdk then has the drop down menu that says none, there is no longer a 'new' button. 然后显示android sdk的下拉菜单中没有任何内容,不再有“新”按钮。

  • 5.) 5.)

    • a.)click the ... to the right of none. a。)单击无的右边的...。
    • b.)click the + in the top left of new window dialog. b。)单击新窗口对话框左上方的+。 (Add new Sdk) (添加新的SDK)
    • c.)click android sdk from drop down menu c。)从下拉菜单中单击android SDK
    • d.)select home directory for your android sdk d。)为您的android SDK选择主目录
    • e.)select java sdk version you want to use e。)选择要使用的Java SDK版本
    • f.)select android build target. f。)选择android build目标。
    • g.)hit ok! g。)打OK!

Once I have followed all these steps, I start to receive error messages in all android classes calls like: 完成所有这些步骤后,我开始在所有android类调用中收到错误消息,例如:

无法解析Android类

I revolved that including android.jar in the SDKs Platform Settings: 我讨论了在SDK平台设置中包括android.jar的问题:

SKD类路径

Just in case someone is lost. 以防万一有人迷路了。 For both new application or existing ones go to File->Project Structure. 对于新应用程序还是现有应用程序,请转到文件->项目结构。 Then in Project settings on the left pane select Project for the Java SDK and select Modules for Android SDK. 然后在左窗格的项目设置中,为Java SDK选择项目,然后为Android SDK选择模块。

I had some issues that this didn't address in getting this environment set up on OSX. 在OSX上设置此环境时,我遇到了一些无法解决的问题。 It had to do with the solution that I was maintaining having additional dependencies on some of the Google APIs. 这与我维持对某些Google API的其他依赖关系的解决方案有关。 It wasn't enough to just download and install the items listed in the first response. 仅下载并安装第一个响应中列出的项目还不够。

You have to download these. 您必须下载这些。

  1. Run Terminal 运行终端
  2. Navigate to the android/sdk directory 导航到android / sdk目录
  3. Type "android" You will get a gui. 输入“ android”,您将得到一个gui。 Check the "Tools" directory and the latest Android API (at this time, it's 4.3 (API 18)). 检查“工具”目录和最新的Android API(当前为4.3(API 18))。
  4. Click "Install xx packages" and go watch an episode of Breaking Bad or something. 单击“安装xx软件包”,然后观看Breaking Bad之类的节目。 It'll take a while. 待会儿
  5. Go back to IntelliJ and open the "Project Structure..." dialog (Cmd+;). 返回IntelliJ并打开“项目结构...”对话框(Cmd +;)。
  6. In the left panel of the dialog, under "Project Settings," select Project. 在对话框的左面板中的“项目设置”下,选择“项目”。 In the right panel, under "Project SDK," click "New..." > Android SDK and navigate to your android/sdk directory. 在右面板的“ Project SDK”下,单击“新建...”> Android SDK,然后导航到android / sdk目录。 Choose this and you will be presented with a dialog with which you can add the "Google APIs" build target. 选择此项,您将看到一个对话框,可以在其中添加“ Google API”构建目标。 This is what I needed. 这就是我所需要的。 You may need to do this more than once if you have multiple version targets. 如果您有多个版本目标,则可能需要执行多次。
  7. Now, under the left pane "Modules," with your project selected in the center pane, select the appropriate module under the "Dependencies" tab in the right pane. 现在,在左窗格的“模块”下,在中央窗格中选择了您的项目,然后在右窗格的“依赖项”选项卡下选择适当的模块。

Another way to identify the correct SDK is to install Android Studio, create a new project, go to project structure, SDK Location and find where the SDK was installed. 识别正确的SDK的另一种方法是安装Android Studio,创建新项目,转到项目结构,SDK位置并找到SDK的安装位置。

I found using the default installation process on a mac that the SDK home folder was in the /Users/'yourUser'/Library/Android/sdk folder. 我发现在Mac上使用默认安装过程时,SDK主文件夹位于/Users/'yourUser'/Library/Android/sdk文件夹中。 Make sure you have enabled your Mac to view the Library folder. 确保已启用Mac来查看“ 库”文件夹。

You just need to install Android development kit from http://developer.android.com/sdk/installing/studio.html#Updating 您只需要从http://developer.android.com/sdk/installing/studio.html#Updating安装Android开发工具包

and also Download and install Java JDK (Choose the Java platform) 并下载并安装Java JDK(选择Java平台)

define the environment variable in windows System setting https://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows 在Windows中定义环境变量系统设置https://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows

Voila ! 瞧! You are Donezo ! 你是Donezo!

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

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