1
votes

I want to execute gradle command from php to build android apk with different application Id and application Name

PHP

exec("cd D:\androidApp && gradlew assembleDebug  -PapplicationId=" . $applicationId . " -PapplicationName=" . $applicationName, $output_array);

build.gradle

android {

def getMyApplicationId = { ->
    def appId = project.hasProperty('applicationId') ? applicationId : "com.example.test"
    println "ApplicationId is set to $appId"
    return appId
}
def getMyApplicationName = { ->
    def name = project.hasProperty('applicationName') ?  applicationName: "Test"
    println "ApplicationName is set to $name"
    return name
}

compileSdkVersion 28
defaultConfig {
    applicationId getMyApplicationId()
    minSdkVersion 17
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}


buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
        resValue("string", "app_name", getMyApplicationName())

    }
    debug {
        resValue("string", "app_name", getMyApplicationName())
        debuggable true
        applicationIdSuffix '.debug'
        versionNameSuffix '-DEBUG'

    }
}}

the output result is:

0 => 'Active code page: 65001'
1 => 'Parallel execution is an incubating feature.'
2 => 'ApplicationId is set to net.yasux.asdfsafsdf'
3 => 'ApplicationName is set to sdfsadfsf'
4 => 'ApplicationName is set to sdfsadfsf'
5 => ':app:checkDebugClasspath UP-TO-DATE'
6 => ':app:preBuild UP-TO-DATE'
7 => ':app:preDebugBuild UP-TO-DATE'
8 => ':app:compileDebugAidl NO-SOURCE'
9 => ':app:compileDebugRenderscript UP-TO-DATE'
10 => ':app:checkDebugManifest UP-TO-DATE'
11 => ':app:generateDebugBuildConfig'
12 => ':app:prepareLintJar UP-TO-DATE'
13 => ':app:mainApkListPersistenceDebug UP-TO-DATE'
14 => ':app:generateDebugResValues'
15 => ':app:generateDebugResources'
16 => ':app:mergeDebugResources FAILED'
17 => '9 actionable tasks: 3 executed, 6 up-to-date'

16 => ':app:mergeDebugResources FAILED'

I tried to execute this command in cmd windows the apk Will create success while in php failed

what's the source of the error?

Thanks in advance :)

1

1 Answers

1
votes

Solution :

First you want to set execution time before execute command

ini_set('max_execution_time', 1250);

Second you want to clean build cache in android by adding cleanBuildCache to the execution command.

Third set the project directory for android in your command by adding --project-dir D:\androidApp

exec("D:\androidApp\gradlew.bat cleanBuildCache assembleDebug --project-dir D:\androidApp -PapplicationId=" . $model->applicationId . " -PapplicationName=" . $model->applicationName, $output_array);