AndroidStudio建立Module報錯
阿新 • • 發佈:2019-01-28
前言
最新升級了AndroidStudio,在當前專案裡建立module的時候,出現了下面的錯誤
com.android.tools.idea.templates.FreemarkerUtils$TemplateProcessingException:
這個錯誤是Android內部產生了錯誤,導致無法建立專案,下面記錄一下解決方案。
解決方案
1.關閉AndroidStudio
2.進入AndroidStudio的安裝目錄中的這個資料夾下,我的路徑如下
D:\SorftWare\AndroidStudio\plugins\android\lib\templates\gradle -projects\NewAndroidModule
在這個目錄下找到recipe.xml.ftl檔案,用文字編輯器開啟
3.用下面的內容替換檔案內容
<?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>
4.替換之後儲存,重啟AndroidStudio,便可以正常建立Module了。