Android studio意外问题的解决方式

本文介绍了在使用Android Studio时可能遇到的一些问题及其解决方案,包括:Gradle项目信息加载失败、第三方库引入错误、Debug时使用第三方签名、DevicePolicyManager的异常处理、忽略Lint的“未翻译”错误以及自定义Apk包名的方法。通过这些解决策略,可以帮助开发者更顺利地进行Android应用开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于AndroidStudio的不成熟,在使用过程中经常出现意外的问题,下面介绍下偶遇到的问题,以及解决方法。

1.building “project name”gradle project info

   在启动项目时经常遇到弹出building“project name”gradle project info...提示框,并且一直在圈圈。

   这是因为当前项目的使用到的gradle不合适,需要从官网上重新下载,但又对防问不到google,这就出现一直在圈圈。

   既然无法直接下载,可以选择翻墙,也可以从其他网站找找相应的gradle(提供个gradle2.4 http://download.youkuaiyun.com/detail/nacl025/9146511)

   下载成功后,存放在:C:\Users\用户名\.gradle\wrapper\dists\gradle-1.XX-all\3jdgemv0iv8uqohg3kcp2o88r1\gradle-1.XX-all.zip

   重启Android Studio,如果运气不好的话,还会弹出building“project name”gradle project info。这是因为没有读到相应路径,需要手动把项目目录下的build.idea.gradle等文件及文件夹删除,然后重启AndroidStudio,手动指定相应路径。恭喜,成功了!

2、引用第三方类库

      在有第三类库的时候,运行项目时会发现下面的问题:“android studio Execution failed for task ':app:dexDebug'.”

      这是因为第三方库是系统库,我们运行时不需要添加到安装包内,既所说的Framework_lib。此时我们需要在依赖中做如下修改:

      dependencies {
                         provided files('framework_libs/framework_base.jar')
       }

      特别注意一点jar包不要存放到默认的libs目录内。

3、Debug时使用第三方签名

      android {
               signingConfigs {
                                                      debug {
                                                              storeFile file("D:\\Users\\edmund\\.android\\mdm_test.keystore")
                                                                   }
                                            }
                     }

4、addUserRestriction

  在android5.0后,DevicePolicyManager类新增加了addUserRestriction方法,但是在使用时签名打包时会发生异常,这是混淆引起的,需要在混淆文件里添加下面内容:

    dontwarnandroid.app.admin.DevicePolicyManager

 

5、Lint: How to ignore “<key> is not translated in <language>” errors?

  • "File" > "Settings" and type "MissingTranslation" into the search box
  • 如果还不可以,如下:
  • android {    lintOptions {        checkReleaseBuilds false        // Or, if you prefer, you can continue to check for errors in release builds,        // but continue the build even when errors are found:        abortOnError false    }}

6、自定义导出Apk包名

     打gabuild.gradle文件

apply plugin: 'com.android.application'

//获取时间戳
def getDate() {
    def date = new Date()
    def formattedDate = date.format('yyyyMMddHHmm')
    return formattedDate
}

//从androidManifest.xml中获取版本号
def getVersionNameFromManifest() {
    def manifestParser = new com.android.builder.core.DefaultManifestParser()
    return manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
}

//从androidManifest.xml中获取Code
def getVersionCodeFromManifest() {
    def manifestParser = new com.android.builder.core.DefaultManifestParser()
    return manifestParser.getVersionCode(android.sourceSets.main.manifest.srcFile)
}
android {
    compileSdkVersion 23
    buildToolsVersion '23.0.0'
    defaultConfig {
        applicationId "com.nq.**"
        minSdkVersion 16
        targetSdkVersion 23
    }
    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def file = output.outputFile
            def filename = "Safelauncher_" + getVersionCodeFromManifest() +".apk"
            output.outputFile = new File(file.parent, filename)
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值