Unity與Android的問題

來源:互聯網
上載者:User

標籤:jdk   android   unity   r.java   appcompat   

先說下自己的開發環境

Win7 x64

Unity5.2.2

Android Studio 2.3.2(以下簡稱AS)

JDK1.7


再說下建立項目

在AS中建立一個新項目

用empty activity

將Unity中的classes.jar考到項目下libs檔案夾下,並右鍵->Add as Library

裡面各種修改,最後要Build APK,發布出app-debug.aar檔案

用解壓程式開啟此aar檔案

刪除其中的libs檔案夾

將此檔案及AndroidManifest檔案考到Unity項目

Assets/Plugins/Android  檔案夾下

Unity中發布Android,注意包名和你AS項目的包名一至

我建的Unity測試專案是一個很簡單的情境,就是像機看著幾個Cube


流程如上,但是會報出很多錯誤,要解決這些問題就要如下操作。


首先

在AS中建立Android項目時

最後一頁有一個選項:Backwards Compatibility(AppCompat)

這個選項不要勾選上,我的Unity跟AppCompat可能有不共戴天之仇吧


其次,JDK版本

我原先是1.7,會報出如下

Failed to compile resources with the following parameters: -bootclasspath "/Users/alex/development/adt-bundle-mac-x86_64-20131030/sdk/platforms/android-21/android.jar" -d "/Users/alex/Documents/development/unity/Maze/Maze/Temp/StagingArea/bin/classes" -source 1.6 -target 1.6 -encoding UTF-8 "com/facebook/android/R.java" "com/google/android/gms/R.java" 


這樣的錯誤,在StackOverFlow上的人們解答是把JDK升級到1.8

我照做了,OK了


最後,在MainActivity中的onCreate方法中第二行語句


setContentView(R.layout.activity_main);

這行必須注釋掉,不然裝上apk運行就報錯退出



到此,我們的Unity項目可以成功發布成Android APK了


本文出自 “樹下野獸” 部落格,請務必保留此出處http://shuxiayeshou.blog.51cto.com/4452347/1932216

Unity與Android的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.