2016-10-18 40 views
2

我將Android Studio更新爲2.2.1,但是我創建了一個新項目,我得到了RuntimeException。Android Studio無法創建新項目

java.lang.RuntimeException: 
com.android.tools.idea.templates.FreemarkerUtils$TemplateProcessingException: 
freemarker.core.ParseException: Parsing error in template 
"root://gradle-projects/NewAndroidModule/recipe.xml.ftl" in line 6, 
column 2:Unknown directive: #ifues. Help (latest version): 
http://freemarker.org/docs/ref_directive_alphaidx.html; you're using 
FreeMarker 2.3.20. 
+1

你採取什麼步驟來創建新的項目? –

+0

file-> new - > new project then,next,next,finish(default step)。@ Code-Apprentice .sorry我第一次問問題。 –

+0

嘗試使緩存無效並重新啓動 –

回答

0

出於某種原因,您的模板文件在安裝過程中被破壞。

讓我附上我的文件如下。要申請,請按照以下步驟操作。

  1. 關閉Android Studio。
  2. C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidModule目錄用文本編輯器(如記事本++)
  3. 複製和粘貼下面的代碼,然後保存打開recipe.xml.ftl文件。 (UTF-8格式)
  4. 重新運行Android Studio。

注意該文件是從Android的Studio版本2.2.1

<?xml version="1.0"?> 
<recipe> 

<#if backwardsCompatibility!true> 
    <dependency mavenUrl="com.android.support:appcompat-v7:${buildApi}.+"/> 
</#if> 

<#if unitTestsSupported> 
    <dependency mavenUrl="junit:junit:4.12" gradleConfiguration="testCompile" /> 
</#if> 

<#if !createActivity> 
    <mkdir at="${escapeXmlAttribute(srcOut)}" /> 
</#if> 

    <mkdir at="${escapeXmlAttribute(projectOut)}/libs" /> 

    <merge from="root/settings.gradle.ftl" 
      to="${escapeXmlAttribute(topOut)}/settings.gradle" /> 
    <instantiate from="root/build.gradle.ftl" 
        to="${escapeXmlAttribute(projectOut)}/build.gradle" /> 
    <instantiate from="root/AndroidManifest.xml.ftl" 
        to="${escapeXmlAttribute(manifestOut)}/AndroidManifest.xml" /> 

<mkdir at="${escapeXmlAttribute(resOut)}/drawable" /> 
<#if copyIcons && !isLibraryProject> 
    <copy from="root/res/mipmap-hdpi" 
      to="${escapeXmlAttribute(resOut)}/mipmap-hdpi" /> 
    <copy from="root/res/mipmap-mdpi" 
      to="${escapeXmlAttribute(resOut)}/mipmap-mdpi" /> 
    <copy from="root/res/mipmap-xhdpi" 
      to="${escapeXmlAttribute(resOut)}/mipmap-xhdpi" /> 
    <copy from="root/res/mipmap-xxhdpi" 
      to="${escapeXmlAttribute(resOut)}/mipmap-xxhdpi" /> 
    <copy from="root/res/mipmap-xxxhdpi" 
      to="${escapeXmlAttribute(resOut)}/mipmap-xxxhdpi" /> 
</#if> 
<#if makeIgnore> 
    <copy from="root/module_ignore" 
      to="${escapeXmlAttribute(projectOut)}/.gitignore" /> 
</#if> 
<#if enableProGuard> 
    <instantiate from="root/proguard-rules.txt.ftl" 
        to="${escapeXmlAttribute(projectOut)}/proguard-rules.pro" /> 
</#if> 
<#if !(isLibraryProject??) || !isLibraryProject> 
    <instantiate from="root/res/values/styles.xml.ftl" 
        to="${escapeXmlAttribute(resOut)}/values/styles.xml" /> 
<#if buildApi gte 22> 
    <copy from="root/res/values/colors.xml" 
      to="${escapeXmlAttribute(resOut)}/values/colors.xml" /> 
</#if> 
</#if> 

    <instantiate from="root/res/values/strings.xml.ftl" 
        to="${escapeXmlAttribute(resOut)}/values/strings.xml" /> 

    <instantiate from="root/test/app_package/ExampleInstrumentedTest.java.ftl" 
        to="${escapeXmlAttribute(testOut)}/ExampleInstrumentedTest.java" /> 

<#if unitTestsSupported> 
    <instantiate from="root/test/app_package/ExampleUnitTest.java.ftl" 
        to="${escapeXmlAttribute(unitTestOut)}/ExampleUnitTest.java" /> 
</#if> 
<#if includeCppSupport!false> 
    <instantiate from="root/CMakeLists.txt.ftl" 
        to="${escapeXmlAttribute(projectOut)}/CMakeLists.txt" /> 

    <mkdir at="${nativeSrcOut}" /> 
    <instantiate from="root/native-lib.cpp.ftl" to="${nativeSrcOut}/native-lib.cpp" /> 
</#if> 

</recipe> 
+0

謝謝。它生效。但它顯示另一個異常,意味着ApplicationTest.java.ftl未找到,因此我註釋 –

+0

我註釋在您提供的文件中編譯成功 –

+0

@why_rookie //我建議您卸載AndroidStudio,移除'C:\ Program Files \ Android \ Android Studio'文件夾,然後重新安裝。一般情況下不應該發生,所以其他一些文件也可能被破壞。 – Youngjae