apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.66k stars 1.55k forks source link

Not run android apk with multiple Flavors #1356

Open horaas opened 3 years ago

horaas commented 3 years ago

Bug Report

Not run android apk with multiple Flavors, when using the command "cordova run android"

Problem

What is expected to happen?

the app is expected to run with custom flavors

What does actually happen?

I have the following configuration

my build-extras.gradle

def outputFileNameGeneral
def fileName

if (project.hasProperty('projectName')) {
   fileName = projectName
} else {
   fileName = project.name
}

def environmentProperties = new Properties()
def hascountryProperties = rootProject.file("environment.properties")
def cdvBuildEnvironment
def manifest = new XmlSlurper().parse(file(android.sourceSets.main.manifest.srcFile))

if (hascountryProperties.exists()) {
    environmentProperties.load(new FileInputStream(hascountryProperties))
    cdvBuildEnvironment = environmentProperties['cdvBuildEnvironment']
}

android {
    useLibrary 'org.apache.http.legacy'
    buildTypes {
        debug {
            debuggable true
        }
        release {
           debuggable false
        }
    }

flavorDimensions  "environment"

productFlavors {
    if (cdvBuildEnvironment == "developer") {
        developer {
            dimension "environment"
            buildConfigField "String", "environment", "\"dev\""
        }
    }
    if (cdvBuildEnvironment == "production") {
        production {
            dimension "environment"
            buildConfigField "String", "environment", "\"prod\""
        }
    }
}
outputFileNameGeneral = "${fileName}-${cdvBuildEnvironment}-${manifest."@android:versionCode".text()}"
setProperty("archivesBaseName", "${outputFileNameGeneral}")
}

android.applicationVariants.all { variant ->
    variant.outputs.all { output ->
        outputFileName = "${outputFileNameGeneral}.apk"
    }
}

my enviroment.properties cdvBuildEnvironment=developer or production

Command or Code

when using the command "cordova run android" the following result is obtained platforms/android/app/build/outputs/apk/developer/debug/app-developer-10000.apk

in console Could not find any APKs to deploy

Version information

cordova cli 10.0.0 cordova android 10.1.1 npm 7.13.0 node 14.17.0

hejercherbib commented 3 years ago

I have the same problem with error : Could not find any APKs to deploy Any suggestion ?

hejercherbib commented 3 years ago

it seems to be related to this https://github.com/apache/cordova-android/issues/1128 but no real solution provided :(