我想从php执行gradle命令以使用不同的应用程序ID和应用程序名称构建android apk
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'
}
}}
输出结果是:
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'
我试图在cmd Windows中执行此命令,而apk将在php中失败而创建成功
错误的根源是什么?
预先感谢:)
答案 0 :(得分:0)
解决方案:
首先要设置执行命令之前的执行时间
ini_set('max_execution_time',1250);
第二,您想通过在执行命令中添加 cleanBuildCache 来清理android中的构建缓存。
通过添加-project-dir D:\ androidApp
在命令中为android设置项目目录exec(“ D:\ androidApp \ gradlew.bat cleanBuildCache assembleDebug- -project-dir D:\ androidApp -PapplicationId =”。$ model-> applicationId。 “ -PapplicationName =”。$ model-> applicationName,$ output_array);