2019-08-03 13:11:46 qq_43420347 阅读数 25

unity3d 升级之后 GooglePlay Services导致版本权限失败问题
很神奇的是 我自己使用锤子手机 或者模拟器跑包正常 其他大部分手机导致网络连接失败
使用adb 找到日志 发现是GooglePlay Services 引起的
错误日志一: Rejecting re-init on previously-failed class java.lang.Class<com.mob.tools.network.NetworkHelper$6>: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/methods/HttpEntityEnclosingRequestBase
解决方法是在Plugins\Android\AndroidManifest 文件里增加一条权限

在这里插入图片描述
解决之后 再次打包 发现依然无法获取网络权限 再次查看日志
错误日志二:Cleartext HTTP traffic to test.xx.xx not permitted(app的包名就不写了)
解决方式差不多在文件内加入 android:usesCleartextTraffic=“true”
在这里插入图片描述

https://blog.csdn.net/u012556114/article/details/88572644
https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted
这两个地址 更加的详细 可以参考

2018-02-26 17:31:37 zhenghongzhi6 阅读数 341

本文首发于“洪流学堂”微信公众号。
洪流学堂,让你快人几步成为Unity大牛!

目前(2018年2月26日)Unity打包Android不支持JDK9

https://forum.unity.com/threads/java-9-jdk-9-support-by-unity-android.499354/

安装JDK8!

安装JDK8!

安装JDK8!



交流群:492325637
关注“洪流学堂”微信公众号,让你快人几步成为Unity大牛

2018-07-05 11:02:00 AnYuanLzh 阅读数 2565

unity版本:2017.4.3f1
unity gradle android打包出aaptOptions.noCompress数组太大导致打包失败问题.
将unity安装目录下的mainTemplate.gradle文件中的**STREAMING_ASSETS**去掉即可。

aaptOptions {
        noCompress '.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**
    }

改成:

aaptOptions {
        noCompress '.unity3d', '.ress', '.resource', '.obb'
    }
2018-06-22 17:57:51 qq_36512517 阅读数 286
///
///通过tomcat服务器进行下载ab包

///

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class UpdateAssetBundles : MonoBehaviour
{
/// <summary>
/// 配表路径
/// </summary>
List<string> mainPath;
/// <summary>
/// 配表信息
/// </summary>
Dictionary<string, List<string>> tablePath;
/// <summary>
/// 进入游戏进行资产更新
/// </summary>
public void FirstUpdateAB()
{
StartCoroutine(IEFirstUpdateAB());
}
IEnumerator IEFirstUpdateAB()
{
//进入游戏先检测persistent目录下是否有文件,没有则表示为第一次进游戏,
//需要将streaming目录下的文件拷贝到该目录下。
if (!Directory.Exists(AssetPath.persistentPath))
{
Debug.Log("解压本地文件!(该步骤不需要流量)");
//注意,在Android中,StreamingAssets中的文件包含在一个.jar压缩文件(基本上与标准的zip为统一格式)中,所以只能用
//WWW读取,否则要使用第三方软件来读取,不能用C#的文件读取方法。
List<string> streamList = new List<string>();
yield return StartCoroutine(IECStomcat(AssetPath.streamingPath + "/" + IP.preloadedPath, streamList));
string tableStr = "";
for (int i = 0; i < streamList.Count; i++)
{
tableStr += streamList[i];
tableStr += Environment.NewLine;
string relativePath = "/" + streamList[i].Split(';')[0];
yield return StartCoroutine(IEUpdateAssetBundle(Application.streamingAssetsPath + relativePath.Replace('\\','/'), Application.persistentDataPath + relativePath.Replace('\\', '/')));
}
Debug.Log("解压完成!");
CreadTextFile(AssetPath.persistentPath + "/" + IP.preloadedPath, tableStr);
yield return new WaitForSeconds(0);
}
//获取主配表
Debug.Log("获取服务器列表!(建议在WiFi下更新)");
mainPath = new List<string>();
yield return StartCoroutine(IECStomcat(IP.ResoucelsIP + AssetPath._Android + "/" + IP.ResoucelsTablePath, mainPath));
Debug.Log("检测是否需要更新!");
if (mainPath != null)
{
tablePath = new Dictionary<string, List<string>>();
for (int i = 0; i < mainPath.Count; i++)
{
List<string> list = new List<string>();
tablePath.Add(mainPath[i], list);
yield return StartCoroutine(IECStomcat(IP.ResoucelsIP + mainPath[i], list));
}
}
else
{
Debug.Log("服务器更新失败!找不到主配置文件!");
}
List<string> updateTable = ContrastDetection(tablePath);
Debug.Log("检测到有" + updateTable.Count + "个文件需要更新!");
yield return new WaitForSeconds(0.5f);
if (updateTable.Count > 0)
{
Debug.Log("开始更新资源文件!");
for (int i = 0; i < updateTable.Count; i++)
{
string serverPathAB = IP.ResoucelsIP + updateTable[i].Split(';')[0];
string localPathAB = Application.persistentDataPath + "/" + updateTable[i].Split(';')[0];
yield return StartCoroutine(IEUpdateAssetBundle(serverPathAB.Replace('\\', '/'), localPathAB.Replace('\\', '/')));
}
Debug.Log("资源文件已更新完毕!");
Debug.Log("开始更新配置文件!");
readText(tablePath);
yield return new WaitForSeconds(0.5f);
Debug.Log("配置文件已更新完成!");
}
Debug.Log("进入游戏!");
}




/// <summary>
/// 在安卓平台下判断该条路径是否为 "jar:file"开头(返回true为是)
/// </summary>
/// <returns></returns>
public bool jarFilePath(string path)
{
if (Application.platform == RuntimePlatform.Android && path.Substring(0, AssetPath.jarHead.Length) == AssetPath.jarHead)
{
return true;
}
return false;
}
/// <summary>
/// 判断该条路径是否为"http"开头(返回true为是)
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public bool httpPath(string path)
{
if (path.Substring(0, AssetPath.httpHead.Length) == AssetPath.httpHead)
{
return true;
}
return false;
}


/// <summary>
/// 获取配表,并把每行的信息写入列表中
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
IEnumerator IECStomcat(string path, List<string> mainPath)
{
string[] pathAll;
if (jarFilePath(path) || httpPath(path))
{
//这里有个问题,加了时间戳只有第一个链接能访问到
//if (httpPath(path))
//{
// string nn = DateTime.Now.Ticks.ToString();
// path = path + "?a=" + nn.Substring(nn.ToString().Length - 6);
//}
WWW www = new WWW(path);
yield return www;
if (www.error != null)
{
Debug.Log(www.error+" "+ path);
yield break;
}
pathAll = www.text.Split(Environment.NewLine.ToCharArray());
}
else
{
pathAll= File.ReadAllText(path).Split(Environment.NewLine.ToCharArray());
}
for (int i = 0; i < pathAll.Length; i++)
{
if (pathAll[i] != "")
{
mainPath.Add(pathAll[i]);
}
}
}
/// <summary>
/// 服务器配表与本地配表进行检测比对
/// </summary>
/// <param name="d"></param>
public List<string> ContrastDetection(Dictionary<string, List<string>> d)
{
string path = "";
List<string> listPath = new List<string>();
if (Application.platform == RuntimePlatform.WindowsEditor)
{
path = Application.dataPath + "/" + AssetPath.StreamingAssets;
}
else if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
{
path = Application.persistentDataPath;
}
//遍历配表
foreach (var item in d)
{
string file = "";
string localPath = path + "/" + item.Key;
//检测本地配表是否存在
if (File.Exists(localPath))
{
//本地有该配表就将路径进行比对添加到列表中
file = File.ReadAllText(localPath);
}
for (int i = 0; i < item.Value.Count; i++)
{
if (!file.Contains(item.Value[i]))
{
listPath.Add(item.Value[i]);
}
}
}
return listPath;
}
/// <summary>
/// 从服务器上下载ab包到本地,(注意斜杠,一定要把所有的反斜杠转成斜杠)
/// </summary>
/// <param name="path">服务器路径</param>
/// <param name="localPath">本地路径</param>
/// <returns></returns>
IEnumerator IEUpdateAssetBundle(string path, string localPath)
{
if (httpPath(path))
{
string nn = DateTime.Now.Ticks.ToString();
path = path + "?" + nn.Substring(nn.ToString().Length - 6);
}
WWW www = new WWW(path);
yield return www;
if (www.error != null)
{
Debug.Log("错误信息:" + www.error);
yield break;
}
else
{
string headLocalPath = pathRoundOff(localPath);
if (!Directory.Exists(headLocalPath))
{
Directory.CreateDirectory(headLocalPath);
}
if (File.Exists(localPath))
{
File.Delete(localPath);
}
FileStream steam = File.Create(localPath);
steam.Close();
File.WriteAllBytes(localPath, www.bytes);
}
}
/// <summary>
/// 更新配表
/// </summary>
/// <param name="dateList"></param>
public void readText(Dictionary<string, List<string>> dateList)
{

string directoryPath = Application.persistentDataPath + "/" + AssetPath._Android + "/" + AssetPath.ConfigurationFilesName;
//清除所有配表
if (Directory.Exists(directoryPath))
Directory.Delete(directoryPath, true);
Directory.CreateDirectory(directoryPath);
//创建新的配表
foreach (var item in dateList)
{
string loaclPath = Application.persistentDataPath + "/" + item.Key;
string str = "";
for (int i = 0; i < item.Value.Count; i++)
{
str += item.Value[i];
str += Environment.NewLine;
}
CreadTextFile(loaclPath, str);
}
}
/// <summary>
/// 创建文档文件
/// </summary>
/// <param name="path"></param>
/// <param name="str"></param>
public void CreadTextFile(string path, string str)
{
string headPath = pathRoundOff(path);
if (!Directory.Exists(headPath))
Directory.CreateDirectory(headPath);
File.WriteAllText(path, str);
}

/// <summary>
/// 截取文件的文件夹路径
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public string pathRoundOff(string path)
{
string[] newPath = path.Split('\\');
if (newPath.Length <= 1)
{
newPath = path.Split('/');
}
return path.Substring(0, path.Length - newPath[newPath.Length - 1].Length - 1);
}
}

public class AssetPath
{
/// <summary>
/// 需要打包的文件夹路径
/// </summary>
public static string OriginalPath = Application.dataPath + "/AssetBundleResources/Resources";
/// <summary>
/// 打包出来的文件夹路径
/// </summary>
public const string StreamingAssetsPath = @"Assets/StreamingAssets";
/// <summary>
/// 配置文件夹
/// </summary>
public const string ConfigurationFilesName = "configuration";
/// <summary>
/// 资源文件夹
/// </summary>
public const string ResourcesFilesName = "resources";
/// <summary>
/// 资源文件后缀名
/// </summary>
public const string unity3dSuffix = ".unity3d";
/// <summary>
/// .meta后缀名
/// </summary>
public const string metaSuffix = ".meta";
/// <summary>
/// 打包目录
/// </summary>
public const string StreamingAssets = "StreamingAssets";
/// <summary>
/// Android
/// </summary>
public const string _Android = "Android";
/// <summary>
/// IPhonePlayer
/// </summary>
public const string _IPhonePlayer = "IPhonePlayer";
/// <summary>
/// 移动端本地压缩包路径
/// </summary>
public static string streamingPath = Application.streamingAssetsPath + "/" + Application.platform;
/// <summary>
/// 移动端资产放置路径
/// </summary>
public static string persistentPath = Application.persistentDataPath + "/" + Application.platform;
/// <summary>
/// 预留物配表相对路径
/// </summary>
public const string scheduledFileName = "/"+ConfigurationFilesName+"/prefad/scheduled.txt";
/// <summary>
/// "jar:file"
/// </summary>
public const string jarHead = "jar:file";
/// <summary>
/// "http"
/// </summary>
public const string httpHead = "http";

/// <summary>
/// 配置物
/// </summary>
public const string source = "source";

}


2013-07-18 22:00:00 iteye_19683 阅读数 45

      昨天想要给Murphy同学编译一个Andorid版本的工程,但我本机没有Android SDK,于是安装了Murphy发给我的安装包,并升级设置,结果在发布的最后出现了如下错误:

Error building Player: Exception: android (invokation failed)
ERROR: unknown error
cmd:android list target -c
stdout;
stderr:
Exception in thread "main" java.lang.NullPointerException at SDKMain.main(SDKMain.java:62)

      一时不知道为何,以为当前系统的jre不符合要求,于是去下载了最新的jre安装,依然不可以,后来去unity的论坛搜到了很多遇到该情况的帖子,按照其中一篇的方法最终解决了问题。原文地址:http://forum.unity3d.com/threads/176737-unknown-error-when-building-simple-scene

大体意思是说:

从Android SDK r22开始,基于现有的“platform-tools”组件,又增加了一个新的编译工具SDK组件,以此来降低编译工具和IDE之间的版本耦合性,这样一来,以后升级SDK,就不需要IDE跟着一起升级。详见官方说明:http://developer.android.com/tools/sdk/tools-notes.html

如果你同时拥有r21和r22,那么可以发现“platform_tools”目录下内容的区别:

Android r21 platform-tools content:

aapt.exe
adb.exe
AdbWinApi.dll
AdbWinUsbApi.dll
aidl.exe
api
dexdump.exe
dx.bat
fastboot.exe
lib
llvm-rs-cc.exe
NOTICE.txt
renderscript
source.properties

   Android r22 platform-tools content:

adb.exe
   AdbWinApi.dll
AdbWinUsbApi.dll
api
fastboot.exe
NOTICE.txt
source.properties

所以正是因为目录结构的和系统的改变,影响了当前Unity版本编译处理,当然了,也许改变还不止这些,所以当前最简单的解决办法有两个:

1:重新安装r21版本;

2:如果你坚持想用当前的r22版本,那么

copy:

$(android-sdk)/build-tools/17.0.0/            <-- 这个目录的内容是api17的编译工具

to:

$(android-sdk)/platform-tools/

方法2不是最好的和彻底的解决办法,但经本人试验,确实可行。

That's all.

希望以上能有所帮助,同时感谢亲爱的Murphy同学的帮助。

 
没有更多推荐了,返回首页