<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>安卓 归档 - 初晴神社</title>
	<atom:link href="https://vki.cc/tag/%e5%ae%89%e5%8d%93/feed/" rel="self" type="application/rss+xml" />
	<link>https://vki.cc/tag/安卓/</link>
	<description>白露的博客</description>
	<lastBuildDate>Thu, 22 Oct 2020 07:39:27 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>

<image>
	<url>https://cdn.vki.cc/wp-content/uploads/2018/03/cropped-icemaplen-1-32x32.png</url>
	<title>安卓 归档 - 初晴神社</title>
	<link>https://vki.cc/tag/安卓/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Unity安卓项目踩坑日记</title>
		<link>https://vki.cc/greattruth/experience/692/</link>
					<comments>https://vki.cc/greattruth/experience/692/#comments</comments>
		
		<dc:creator><![CDATA[白露]]></dc:creator>
		<pubDate>Tue, 23 Apr 2019 09:38:57 +0000</pubDate>
				<category><![CDATA[咸鱼心得]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[Unity 3D]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[安卓]]></category>
		<category><![CDATA[心得]]></category>
		<category><![CDATA[教程]]></category>
		<guid isPermaLink="false">https://bye6.cc/?p=692</guid>

					<description><![CDATA[<p>失踪人口回归~ 最近在研究游戏在安卓平台的打包，遇到了不少坑，特此写个文章记录下~ 1.Unity与安卓的交互 虽然Unity可以直接导出apk安装包，但由于有些方法，比如读取手机相册图片，获取权限等，或者是添加&#8230;</p>
<p><a href="https://vki.cc/greattruth/experience/692/">Unity安卓项目踩坑日记</a>最先出现在<a href="https://vki.cc">初晴神社</a>。</p>
]]></description>
										<content:encoded><![CDATA[<p><span style="color: #808080;"><em>失踪人口回归~</em></span></p>
<blockquote><p>最近在研究游戏在安卓平台的打包，遇到了不少坑，特此写个文章记录下~</p></blockquote>
<h2 id="1-unity%e4%b8%8e%e5%ae%89%e5%8d%93%e7%9a%84%e4%ba%a4%e4%ba%92">1.Unity与安卓的交互</h2>
<p>虽然Unity可以直接导出apk安装包，但由于有些方法，比如读取手机相册图片，获取权限等，或者是添加SDK都不能直接通过Unity实现。我们一般用Unity导出安卓工程，再通过Android Studio修改之后打出apk包。</p>
<p>通常情况下每次打包都需要修改，为了偷懒~</p>
<p>这里提供个堪称一劳永逸的解决办法，请看文章~</p>
<p><span style="color: #ff6600;"><a style="color: #ff6600;" href="https://www.jianshu.com/p/86b275da600e" target="_blank" rel="noopener noreferrer">Unity与Android交互方案优化版</a></span></p>
<p><span style="text-decoration: underline;"><a href="https://www.jianshu.com/p/86b275da600e" target="_blank" rel="noopener noreferrer">https://www.jianshu.com/p/86b275da600e</a></span></p>
<h2 id="2-android-aar%e6%96%87%e4%bb%b6%e4%bf%ae%e6%94%b9">2.Android aar文件修改</h2>
<p><span style="color: #808080;"><em>今天刚踩得坑，麻蛋！</em></span></p>
<p>不同于jar包只能包含java代码，aar包还可以保存贴图等资源，相当于一个后缀是aar的压缩包。有时候第三方sdk提供的也是aar文件，当需要修改里面的东西时，比如删掉里面一个jar<strong>。切记不能采取先解压，删除完毕再压缩回去，后缀改成aar的操作。这样修改后Android Studio用不了！！！</strong></p>
<p>正确方法是以解压的形式打开（不是解压压缩包），一般Windows平台的压缩软件都可以，然后在压缩软件里增加或删除文件操作。</p>
<h2 id="3-android-aar%e6%96%87%e4%bb%b6%e8%af%bb%e5%8f%96">3.Android aar文件读取</h2>
<p><span style="color: #808080;"><em>同上，又是个巨坑，匪夷所思！</em></span></p>
<p>我目前的项目在安卓端是这样的，把用到的sdk和需要在安卓端才能调用的方法打成aar包，然后添加到Unity导出的安卓工程里，但是不知道为什么在运行的时候会报以下的错误;</p>
<p><img  fetchpriority="high"  decoding="async"  class="aligncenter size-full wp-image-694"  src="https://cdn.vki.cc/wp-content/uploads/2019/04/QQ20190423-0.jpg"  alt=""  width="661"  height="83"  srcset="https://cdn.vki.cc/wp-content/uploads/2019/04/QQ20190423-0.jpg 661w, https://cdn.vki.cc/wp-content/uploads/2019/04/QQ20190423-0-300x38.jpg 300w"  sizes="(max-width: 661px) 100vw, 661px" ></p>
<p>说的是BGPlayerService类重复，可是我的找遍了真个项目和aar包也只有一个类，根本没有重复的地方。研究了很久都无解，就在准备放弃治疗的时候顺便改了下build.gradle的dependencies里的语句，从</p>
<pre class="pure-highlightjs"><code class="null">dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':localizedappnamelib')
    implementation 'com.android.support:support-core-utils:24.2.0'
    implementation (name:'findingparadiselib-debug',ext:'aar')
}</code></pre>
<p>改成了</p>
<pre class="pure-highlightjs"><code class="null">dependencies {
    implementation (name:'findingparadiselib-debug',ext:'aar')
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':localizedappnamelib')
    implementation 'com.android.support:support-core-utils:24.2.0'
}</code></pre>
<p>然后特么问题解决了！</p>
<p>？？？</p>
<p>我怀疑可能是implementation fileTree(include: [&#8216;*.jar&#8217;], dir: &#8216;libs&#8217;)把aar包里的jar也算进去了_(:з」∠)_</p>
<h2 id="4-%e7%94%9f%e6%88%90%e7%ad%be%e5%90%8d%e5%ae%89%e8%a3%85%e5%8c%85%e7%9a%84%e6%97%b6%e5%80%99%e6%8a%a5%e9%94%99">4.生成签名安装包的时候报错</h2>
<p>在第一次生成签名安装包的时候可能提示缺少xxx.pom（忘了是不是pom后缀了，反正差不多）和xxx.jar组件，这个报错在生成debug包的时候是不出现的。具体原因我不清楚，我猜是打包的时候需要这样依赖包，但是谷歌的官方站点没有（Android Studio提供的链接点进去404）。</p>
<p>两个解决办法，一是手动下载这些依赖包并放到指定的目录中去，不过不建议这样做，一个一个下载再放到指定目录太麻烦了。</p>
<p>第二中解决方法是使用阿里提供的站点，具体操作是将以下的代码方放到安卓工程的build.gradle文件的repositories代码块中去：</p>
<pre class="pure-highlightjs"><code class="null">maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }</code></pre>
<p>这样打包的时候Android Studio会自动去这些站点下载需要的依赖包，问题解决。</p>
<h2 id="5-execution-failed-for-task-appndkbuild">5.Execution failed for task &#8216;:app:ndkBuild&#8217;.</h2>
<p>该问题是在对一个老游戏升级的时候出现的，表现为无法打包，报错：</p>
<pre class="pure-highlightjs"><code class="null">Process 'command 'D:\SDK\***/ndk-build.cmd'' finished with non-zero exit value 2</code></pre>
<p>上网搜索，普遍的解决方式是使用低版本的NDK，又或者是删除src/main/obj文件夹里的内容，尝试无果。</p>
<p>最终发现是build.gradle版本较老，且使用ndkBuild的方式打包，不适用于新版的Android Studio，修改之后问题解决</p>
<p>修改前：</p>
<pre class="pure-highlightjs"><code class="null">android {
    signingConfigs {
    }
    compileSdkVersion 26
    buildToolsVersion '23.0.3'
    defaultConfig {
        applicationId "com.xd.swords.and"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 18
        versionName "1.1.7"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets.main.jni.srcDirs = []
    // disable automatic ndk-build call, which ignore our Android.mk
    sourceSets.main.jniLibs.srcDir 'src/main/libs'
    // call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        workingDir file('src/main')
        commandLine getNdkBuildCmd()
    }
    tasks.withType(JavaCompile) {
        compileTask -&gt; compileTask.dependsOn ndkBuild
    }
    task cleanNative(type: Exec) {
        workingDir file('src/main')
        commandLine getNdkBuildCmd(), 'clean'
    }
    clean.dependsOn cleanNative
}</code></pre>
<p>修改后：</p>
<pre class="pure-highlightjs"><code class="null">android {
    signingConfigs {
    }
    compileSdkVersion 26
    buildToolsVersion '23.0.3'
    defaultConfig {
        applicationId "com.xd.swords.and"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 18
        versionName "1.1.7"
        ndk {
            abiFilters 'armeabi-v7a'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        ndkBuild {
            path "src/main/jni/Android.mk"
        }
    }

    // 下面部分代码应该也可以删掉。
    sourceSets.main.jni.srcDirs = []
    // disable automatic ndk-build call, which ignore our Android.mk
    sourceSets.main.jniLibs.srcDir 'src/main/libs'
    // call regular ndk-build(.cmd) script from app directory
}</code></pre>
<p>对比前后，主要是删除了旧的ndkBuild代码，然后设置abiFilters等。</p>
<p><a href="https://vki.cc/greattruth/experience/692/">Unity安卓项目踩坑日记</a>最先出现在<a href="https://vki.cc">初晴神社</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vki.cc/greattruth/experience/692/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
