我在Android应用程序的gradle文件中有两种风格:
productFlavors {
production { }
devel { }
}
我有一个配置文件,我需要在构建项目时运行任何其他任务之前将其复制到app/
目录。这是每种风味的配置文件,即:
etc/configuration-production.json
etc/configuration-devel.json
构建devel
时,我需要基本上做到这一点:
cp etc/configuration-devel.json app/configuration.json
构建production
时:
cp etc/configuration-production.json app/configuration.json
如何在gradle中自动执行此操作?这个副本首先需要在执行构建时发生,因为某些任务需要app/configuration.json
文件存在。
我试过了:
task copyConfig(type: Copy) {
from "etc/configuration-${Flavor.name}.json"
into "app/configuration.json"
}
build.dependsOn copyConfig
但没有工作。 copyConfig
任务没有运行。
答案 0 :(得分:1)
您可以将以下内容添加到SandBox sandbox;
public AsteroidField() {
sandbox = new SandBox();
sandbox.setSandBoxMode(FLOW);
...
$TOTAL=0;
$result = mysql_query("SELECT * from HP_Closing_Count WHERE '2017-01-01' <= Date and Date < '2017-02-01'");
echo '<table border=2px>'; // opening table tag
echo'<th>Date</th>
<th>Employee</th>
<th>CashTotal</th>
'; //table headers
while($data = mysql_fetch_array($result))
{
$TOTAL=$TOTAL+$data['CashTotal'];
// we are running a while loop to print all the rows in a table
echo'<tr>'; // printing table row
echo '<td>'.$data['Date'].'</td>
<td>'.$data['Employee'].'</td>
<td>'.$data['CashTotal'].'</td>
'; // we are looping all data to be printed till last row in the table
echo'</tr>'; // closing table row
}
echo '</table>'; //closing table tag
echo $TOTAL;
?>
,以便在相应任务app
和放大器的第一个声明中将文件从build.gradle
复制到etc/configuration-XXX.json
; app/configuration.json
:
assembleDevel.*
这是必需的配置:
assembleProduction.*
如果def cp(copyType) {
println "copying " + "../etc/configuration-" + copyType + ".json"
copy {
from "../etc/configuration-" + copyType + ".json"
into '.'
rename { String fileName ->
fileName.replace("configuration-" + copyType + ".json", "configuration.json")
}
}
}
tasks.whenTaskAdded { task ->
if (task.name ==~ /assembleDevel.*/) {
task.doFirst() {
cp("devel")
}
} else if (task.name ==~ /assembleProduction.*/) {
task.doFirst() {
cp("production")
}
}
}
/ app/
├── build.gradle
etc/
├── configuration-production.json
└── configuration-devel.json
不是您要查找的任务,则可以将其替换为:assembleDevel.*
/ assembleProduction.*