[英]How to make Android Studio/Gradle build from an updated source file?
In my previous Windows/Eclipse/ant project development method I had a means of producing a time-limited release apk from the command line. 在以前的Windows / Eclipse / ant项目开发方法中,我有一种从命令行生成有时间限制的发行版apk的方法。 I would like to reproduce this functionality with my new Ubuntu/Android Studio/Gradle setup.
我想通过新的Ubuntu / Android Studio / Gradle设置重现此功能。
This is how the old system worked: 这是旧系统的工作方式:
I had a .bat file which ran a runnable jar which I wrote (and can also create on my new machine). 我有一个.bat文件,该文件运行了我编写的可运行jar(也可以在新计算机上创建)。 That jar takes two arguments expiry date and where to put the output file.
该jar有两个参数,即到期日期和将输出文件放置在何处。 The jar's output is called Timekey.java and it looks like:
该jar的输出名为Timekey.java,它看起来像:
package uk.co.myname.timekey;
public final class Timekey{
public static final String EXPIRY_DATE =
"the encrypted string";
public String getExpiryDate() {
return EXPIRY_DATE;
}
}
// Plain date : 2020-01-01.00_00_00
I have my build.xml checking for the presence of this file 我让我的build.xml检查此文件的存在
<target name="-check-timekey">
<echo>"${timelimit_src}/Timekey.java"</echo>
<available file="${timelimit_src}/Timekey.java" property="timekey.present" />
</target>
and if present it sets the src 如果存在,它将设置src
<if condition="${timekey.present}">
<src path="${timelimit_src}" />
Thus I can produce an apk which will only run up to the date entered as a parameter to the batch file. 因此,我可以生成一个apk,它将仅运行到作为批处理文件的参数输入的日期。 The encryption is not military grade but good enough to defeat amateurs and should stop the de-obfuscation fiends.
加密级别不是军事级别,但是足以击败业余爱好者,并且应该阻止去混淆的恶魔。
Any ideas on how to implement this with gradle will be most welcome. 任何有关如何使用gradle来实现这一点的想法都将受到欢迎。 I know how to run the jar from a bash script but swapping source directories, just for command line release builds has me stumped
我知道如何从bash脚本运行jar,但是交换源目录,只是为了命令行发布版本而感到困惑
I did manage to solve this in the end. 我确实设法解决了这个问题。 I created the build type 'release' which was not previously necessary,as 'main' sufficed.
我创建了以前不需要的构建类型“发布”,因为“主要”就足够了。 I also reated the build type 'timelimited'.
我还提出了构建类型“ timelimited”。 Timekey.java was removed from main and placed in debug, release and timelimited's src/java folders (including the class stucture hierarchical folders).
Timekey.java已从main中删除,并放置在debug,release和timelimited的src / java文件夹(包括类结构层次结构文件夹)中。
This script completed the process 该脚本完成了该过程
#!/bin/bash
# Script to build time limited apk NBT 2nd March 2016
# Must be run from one leve below AndroidStudioProjects folder
# Must have one argument of expiry date in YYYY-MM-DD format
CURRENT_DIR=`pwd`
case "$CURRENT_DIR" in
*AndroidStudioProjects/*) ;;
*) echo "Quitting because of wrong starting directory name"
echo "You must be one folder below ~/AndroidStudioProjects to run this script"
exit 1 ;;
esac
OUTDIR_SUFFIX=/app/src/timelimited/java/uk/co/myname/timekey/
OUTDIR=$CURRENT_DIR$OUTDIR_SUFFIX
echo "Directory to write in: "$OUTDIR
if [ -z "$1" ]
then
echo "argument 1 required, as expiry date in YYYY-MM-DD format, so quitting"
exit 1
fi
EXDATE=$1
case "$EXDATE" in
????-??-??) ;;
*) echo "Quitting because of bad date format on parameter 1"
exit 1 ;;
esac
# the encrypt5.jar requires these two arguments
java -jar ~/runnablejars/encrypt5.jar $EXDATE $OUTDIR
echo " "
echo " "
gradlew assembleTimelimited
cat $OUTDIR/Timekey.java
echo " "
echo "All done, now IF you saw Timekey.java printed out, then"
echo "the time limited apk is built. Run gradlew InstallTimelimited"
echo "to install it on a running device"
while true; do
read -p "Do you wish to install this apk on running device y/n [enter]? " yn
case $yn in
[Yy]* ) gradlew InstallTimelimited; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
I hope this might prove useful. 我希望这可能会有用。 There are probably less convoluted ways of doing it but I don't know one.
可能有比较复杂的方法,但我不知道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.