定位Unity安卓包不易现的Bug方案——在Android Studio里面调试Unity的安卓包

第一步在unity导出项目文件
导出项目
导出的项目目录
第二步把项目导入Android Studio
打开项目
项目标示是安卓头像
第三步打开 build.gradle 文件
文件位置
ps:如果没有找到在右上方进行搜索

然后把内部代码全部替换掉

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    
    repositories {
    
    
        //google()
        //jcenter()
        maven {
    
     url 'https://maven.aliyun.com/repository/public/' }
        maven {
    
     url 'https://maven.aliyun.com/repository/google/'}
        maven {
    
     url 'https://maven.aliyun.com/repository/jcenter/'}
        mavenLocal()
        mavenCentral()
    }
    dependencies {
    
    
        classpath 'com.android.tools.build:gradle:3.5.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    
    
    repositories {
    
    
        //google()
        //jcenter()
        maven {
    
     url 'https://maven.aliyun.com/repository/public/' }
        maven {
    
     url 'https://maven.aliyun.com/repository/google/'}
        maven {
    
     url 'https://maven.aliyun.com/repository/jcenter/'}
        mavenLocal()
        mavenCentral()
    }
}

task clean(type: Delete) {
    
    
    delete rootProject.buildDir
}

注意,这里只是更改了 buildscript 和 allprojects 中的 repositories 代码块。

除此之外,还要更改 gradle-wrapper.properties 文件,找不到也用搜索查

原来的代码是

#Mon Feb 17 18:13:54 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

更改后代码是

#Mon Feb 17 18:13:54 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://downloads.gradle-dn.com/distributions/gradle-5.4.1-all.zip

注意,这里只更改了 distributionUrl。

然后选择同步Gradle
同步组件
同步完成后如图所示
同步成功
然后你可以把Android Studio的调试工具打开,这里我用的是LogCat

这时候可以让你的移动设备通过USB连接到电脑上,然后点击运行
运行程序
过一会你的移动设备会收到安装应用请求,安装后就可以运行调试,测试程序中存在的不易现的问题

猜你喜欢

转载自blog.csdn.net/qq_45506643/article/details/111591236