android开发技巧杂谈

时间:2023-02-05 07:15:59

android的一些常用包是发布在国外的,所以一些包,我们下载不下来,我们可以使用阿里云的镜像地址(maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' })。

使用https的地址,如下(亲测可用):

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

        maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
        google()
        mavenCentral()
        jcenter()
        maven { url "https://jitpack.io"}

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.0-rc01'
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
        classpath 'com.android.tools.build:gradle:7.1.2'


    }
}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
        maven { url 'https://jitpack.io' }
    }
}

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

两个repositories都要添加。

其他参考镜像地址:

maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }

方法二,使用http,可以在仓库前添加allowInsecureProtocol = true,如下(这个我没测试):

maven{
        allowInsecureProtocol = true
        url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}

android开发技巧二

当下载的项目和本地android studio的版本不一致时,在gradle.properties中添加配置如下,可以解决,如下:

android.injected.studio.version.check=false

如下图 

android开发技巧杂谈

android开发技巧三

项目的gradle出问题时,我们是无法编Build的,但通常会弹出一个蓝色对话框,点击try again,可以重新导入项目,如下:

android开发技巧杂谈

android开发技巧四

如果使用了各种方法都解决不了,android studio版本不匹配的问题,那就一定是两个版本确实存在不兼容,那就果断换AS的版本。

比如,AS从4.2以后,也就是4.3开始,版本名字命名方式改了,这就通常意味着AS有了一些大改动。

如果实战遇到android studio4.2和4.3版本不兼容,可以果断换版本。

AS下载地址:https://android-studio.en.softonic.com/download

Can't convert 'UNIFIED_TEST_PLATFORM' to enum type 'BooleanFlag'
Cannot convert string value 'UNIFIED_TEST_PLATFORM' to an enum value of type 'com.android.builder.model.AndroidGradlePluginProjectFlags$BooleanFlag' (valid case insensitive values: APPLICATION_R_CLASS_CONSTANT_IDS, TEST_R_CLASS_CONSTANT_IDS, TRANSITIVE_R_CLASS, JETPACK_COMPOSE, ML_MODEL_BINDING)
Cannot convert string value 'UNIFIED_TEST_PLATFORM' to an enum value of type 'com.android.builder.model.AndroidGradlePluginProjectFlags$BooleanFlag' (valid case insensitive values: APPLICATION_R_CLASS_CONSTANT_IDS, TEST_R_CLASS_CONSTANT_IDS, TRANSITIVE_R_CLASS, JETPACK_COMPOSE, ML_MODEL_BINDING)

android开发技巧五

Android 调试桥 (adb) 是一个通用命令行工具,其允许您与模拟器实例或连接的 Android 设备进行通信。

下载完adb,将里面的文件复制到C:\Users\Administrator,然后我们直接运行cmd,就可以执行adb的命令了。

使用adb安卓调试工具打开一个activity,如下:

启动Activity
adb shell am start com.kiba.app/com.kiba.app.SplashActivity

使用参考网站:https://developer.android.google.cn/studio/command-line/adb?hl=zh-cn(这里也有下载地址,不过得自己找)

下载地址:https://www.onlinedown.net/soft/578131.htm(我在这里下载的,没有广告)

----------------------------------------------------------------------------------------------------

注:此文章为原创,任何形式的转载都请联系作者获得授权并注明出处!
若您觉得这篇文章还不错,请点击下方的【推荐】,非常感谢!

 android开发技巧杂谈