您的位置:首页 > 移动开发 > Android开发

Android 开发中出现的错误解决方法 --安装错误

2018-03-27 15:35 615 查看
在安卓开发中,当我们在安装包的时候会出现一些错误,本文将这些错误记录,待以后查询使用

Failure [INSTALL_FAILED_TEST_ONLY]

The APK file XXX.apk does not exist on disk

1.Failure [INSTALL_FAILED_TEST_ONLY]

平台版本是android 7.0,在adb install *.apk 会提示下面的错误:
Failure [INSTALL_FAILED_TEST_ONLY]

方法1:
修改AndroidManifest.xml 中android:testOnly="true" 改成 android:testOnly="false",或者直接去掉。

方法2:
adb push *.apk /tmp
adb shell pm install -t /tmp/*.apk

方法3:
adb install -t *.apk

方法3已测,没问题。


2.The APK file XXX.apk does not exist on disk

参考文章:The APK file does not exist on disk

如果你使用Android studio 遇到这个问题,那么一般你是想对编译时生成的apk文件进行自定义命名,并且你的命名规则包含动态部分,比如,命名规则中使用了时间戳。由于gradle在执行编译命令和安装命令时有时间差,且调用了两次你的名称规则,导致编译出来的apk名称和安装时获取到的apk名称不一致,所以它就报找不到指定的apk文件了。

一般修改编译后apk文件名,在gradle是这样配置的

android {
applicationVariants.all{variant->
variant.outputs.each{output->
if(variant.buildType.name.equals('release')) {
def oldFile = output.outputFile
def newName = 'dayjoke_V'+defaultConfig.versionName+'_'+getDate()+'-release.apk';
output.outputFile = new File(oldFile.parent, newName)
}
}
}
}

def getDate() {
def date = new Date()
def formattedDate = date.format('yyyy_MM_dd_HH_mm_ss')
return formattedDate
}


但是这种命名规则是到秒级的,所以每次构建和安装时获取的文件名称都不一样,每次都会报错。

解决方案:

1.遇到这个问题时,首先想到的是,如何让编译出来的apk文件名和要安装的文件名相同,而gradle 执行安装的task是installRelease,那么就是如何动态修改installRelease 命令中指定安装的文件名。虽然这是一个方向,但是我并不会耶没有找到修改的方法。最简单的办法就是固定apk的文件名,至少不要使用时间戳这种容易改变的命名规则。

android {
applicationVariants.all{variant->
variant.outputs.each{output->
if(variant.buildType.name.equals('release')) {
def oldFile = output.packageApplication.outputFile
def newName = 'dayjoke_V'+defaultConfig.versionName+'_'+getDate()+'-release.apk';
output.packageApplication.outputFile = new File(oldFile.parent, newName)
}
}
}
}

def getDate() {
def date = new Date()
def formattedDate = date.format('yyyy_MM_dd_HH_mm_ss')
return formattedDate
}


不同之处在于outputFile

output.outputFile




output.packageApplication.outputFile


通过编译执行比较,发现,前者即用来编译出apk文件,也用于安装;而后者,只是编译出apk文件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐