Android studio is using the wrong apk file path when I use my own build.gradle file
So I'm trying to use a custom build file that generates an unsigned apk, then runs a task on it, and then zipaligns. I haven't gotten this job yet. However, I have it creating and signing the apk correctly, but when I try to just hit the play button to start it while debugging on the device using my own debug setting, studio / gradle creates my apk and puts it in the directory I am but it cannot push it to device because it uses a file path that doesn't exist. I / O error: C: \ ProgramData \ Microsoft \ Windows \ Start Menu \ Programs \ Android Studio \ apk \ V2.5-10-debug-20140922-2335.apk (the system cannot find the path specified). Is this hardcoded into the studio build because I can't find a setting to change it.It really makes the whole process a real pain. Infact that path doesn't exist anywhere on my machine.
EDIT heres my build.gradle file
import java.text.SimpleDateFormat
import java.util.regex.Pattern
apply plugin: 'com.android.application'
def buildTime() {
def df = new SimpleDateFormat("yyyyMMdd'-'HHmm")
df.setTimeZone(TimeZone.getDefault())
return df.format(new Date())
}
def apkName = "MyApp"
def apkLocation
task (runApkSigTool , dependsOn: android, type: JavaExec) {
classpath files('apksigtool.jar')
main 'com.widevine.tools.android.apksigtool.ApkSigTool'
args[0] = apkLocation
args[1] = 'private_key.der'
args[2] = 'my.crt'
System.out.println(apkLocation);
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
signingConfigs{
debug{
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release{
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
buildTypes {
debug{
}
release {
signingConfig signingConfigs.release
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
assembleDebug.doLast{
runApkSigTool.execute()
}
zipAlign true
}
debug{
signingConfig signingConfigs.debug
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
assembleDebug.doLast{
runApkSigTool.execute()
}
zipAlign false
}
android.applicationVariants.all { variant ->
def manifestFile = file("C:\\path\\app\\src\\main\\AndroidManifest.xml")
def pattern = Pattern.compile("versionName=\"(.+)\"")
def manifestText = manifestFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def versionName = matcher.group(1)
pattern = Pattern.compile("versionCode=\"(.+)\"")
matcher = pattern.matcher(manifestText)
matcher.find()
def versionCode = matcher.group(1)
if (variant.zipAlign) {
variant.outputFile = new File("apk/"+apkName+"-V"+versionName+"-"+versionCode+"-"+variant.name+"-"+buildTime()+"-unaligned.apk");
variant.zipAlign.inputFile = variant.outputFile
variant.zipAlign.outputFile = new File("apk/"+apkName+"-V"+versionName+"-"+versionCode+"-"+variant.name+"-"+buildTime()+".apk");
} else {
apkLocation = "apk/"+apkName+"-V"+versionName+"-"+versionCode+"-"+variant.name+"-"+buildTime()+".apk";
variant.outputFile = new File("apk/"+apkName+"-V"+versionName+"-"+versionCode+"-"+variant.name+"-"+buildTime()+".apk");
System.out.println("CREATED UNSIGNED APK---------------")
}
}
}
lintOptions {
abortOnError false
ignoreWarnings true
checkAllWarnings false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:mediarouter-v7:20.0.0'
compile 'com.google.android.gms:play-services:5.0.89'
}
source to share
No one has answered this question yet
Check out similar questions: