<Android-SDK>/tools
folder has already got into PATH
. The project is created by the following command:android create project -n < > -t android-< API> -p < > -k < > -a < >
AndroidManifest.xml
, by the way, this 15 will not light up, there will only be 10 as the minimum required API level.android create project -n KillerApp -t android-15 -p KillerApp -k com.damageinc.killerapp -a MainActivity
launch
, which is not in the standard system, but we will do it ourselves. Cleaning is, quite expectedly, clean , and you need to test in Android through a separate, test project, so you can easily erase what is in that field.gen
folder to the source folders, because it is in this folder that the R.java
file will be located.R
file should not be mentioned in the code of our program, since it is in a separate folder. You also need to add the correct Android platform to the list of libraries, in our case it is <Android-SDK>/platforms/android-15/android.jar
.bin/classes
folder so that the IDE knows where to look for the compiled code. In principle, this step is not mandatory, and you can safely spit on it. But for the sake of completeness, I will make it so that NetBeans shows which files have been recently modified and not yet compiled.custom_rules.xml
file , and write in it <project name="CustomRules"> <target name="release-and-save" depends="release"> <xpath input="AndroidManifest.xml" expression="/manifest/@android:versionName" output="manifest.versionName" default="test"/> <xpath input="AndroidManifest.xml" expression="/manifest/@android:versionCode" output="manifest.versionCode" default="test"/> <copy file="${out.final.file}" tofile="releases/${ant.project.name}-release${manifest.versionCode}-${manifest.versionName}.apk" overwrite="true"/> <copy file="${obfuscate.absolute.dir}/mapping.txt" tofile="releases/mapping-release${manifest.versionCode}.txt" overwrite="true"/> </target> <target name="rebuild-resources" depends="-set-debug-mode, -build-setup, -code-gen" /> <target name="-find-main-activity"> <xpath input="AndroidManifest.xml" expression="/manifest/@package" output="project.app.package" default="test"/> <xpath input="AndroidManifest.xml" expression="/manifest/application/activity[intent-filter/category/@android:name = 'android.intent.category.LAUNCHER'][1]/@android:name" output="project.app.mainactivity" default="test"/> <if> <condition> <matches pattern="\..+|[^\.].*\..*[^\.]" string="${project.app.mainactivity}"/> </condition> <then> <property name="project.app.mainactivity.qualified" value="${project.app.mainactivity}"/> </then> <else> <property name="project.app.mainactivity.qualified" value=".${project.app.mainactivity}"/> </else> </if> <property name="project.app.launcharg" value="-a android.intent.action.MAIN -n ${project.app.package}/${project.app.mainactivity.qualified}"/> </target> <target name="launch" depends="-find-main-activity"> <exec executable="adb"> <arg line="shell am start"/> <arg line="${project.app.launcharg}"/> </exec> </target> </project>
rebuild-resources
allows you to generate an R
file (which in Eclipse, by the way, often disappears somewhere or is not updated on time). launch
will give us the opportunity to launch applications, and release-and-save
will ensure that when building the final version, it will be saved in a separate folder under the appropriate name along with the ProGuard method map. I also like to add such lines so that after the build a notification is played: <target name="-post-build"> <sound> <success source="C:\Windows\Media\Windows Notify.wav"/> </sound> </target>
launch
task at the end. I added the rest of the tasks I just made to the user menu of the context menu:project.properties
file :proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
ant.properties
it is worth ant.properties
the lines for signing the final assemblies :key.store = < >
key.alias = < >
build.xml
. Actually, this is just a small tail of the main system, and all it does is loading properties from files with the properties extension and calling the main system located in the SDK itself.local.properties
contains only one property: the location of the folder with the SDK. This file must be added to the list of exceptions of the version control system , because it contains settings specific to a particular machine. For example, on my Windows this file contains the linesdk.dir=C:\\Android-SDK
ANDROID_HOME
environment ANDROID_HOME
with the contents of a variable from this file and safely send the file to the trash. Above all, do not forget to restart NetBeans after this.ant.properties
have already met ant.properties
, there are stored auxiliary variables like the location of the keystore. There is also a project.properties
file. After the actions described in the creation of the project, there are only lines about the level of the Android API for which the project is going, and about where to look for the ProGuard configuration file. When we add to the library project, the lines about them will appear in the same place.proguard-project.txt
file, which, as the name implies, contains instructions from ProGuard. It is initially empty, but this does not mean that ProGuard will run empty, because the SDK folder already has a pre-recorded configuration (remember the uncommented line about ProGuard?), And here we can specify it. For example, I personally love, among other things, to add lines-renamesourcefileattribute MyProject
-keepattributes SourceFile,LineNumberTable
build.xml
loads the file custom_rules.xml
, if it exists, in which we added all the tasks we need. Worth a look at the job again. <target name="rebuild-resources" depends="-set-debug-mode, -build-setup, -code-gen" />
<target name="release-and-save" depends="release"> <xpath input="AndroidManifest.xml" expression="/manifest/@android:versionName" output="manifest.versionName" default="test"/> <xpath input="AndroidManifest.xml" expression="/manifest/@android:versionCode" output="manifest.versionCode" default="test"/> <copy file="${out.final.file}" tofile="releases/${ant.project.name}-release${manifest.versionCode}-${manifest.versionName}.apk" overwrite="true"/> <copy file="${obfuscate.absolute.dir}/mapping.txt" tofile="releases/mapping-release${manifest.versionCode}.txt" overwrite="true"/> </target>
xpath
. Another useful tool, for example, is if
, which does exactly what the corresponding construct does in programming languages: performing one or another task depending on the condition.xpath
, this time the task is a bit more complicated: <target name="-find-main-activity"> <xpath input="AndroidManifest.xml" expression="/manifest/@package" output="project.app.package" default="test"/> <xpath input="AndroidManifest.xml" expression="/manifest/application/activity[intent-filter/category/@android:name = 'android.intent.category.LAUNCHER'][1]/@android:name" output="project.app.mainactivity" default="test"/> <if> <condition> <matches pattern="\..+|[^\.].*\..*[^\.]" string="${project.app.mainactivity}"/> </condition> <then> <property name="project.app.mainactivity.qualified" value="${project.app.mainactivity}"/> </then> <else> <property name="project.app.mainactivity.qualified" value=".${project.app.mainactivity}"/> </else> </if> <property name="project.app.launcharg" value="-a android.intent.action.MAIN -n ${project.app.package}/${project.app.mainactivity.qualified}"/> </target> <target name="launch" depends="-find-main-activity"> <exec executable="adb"> <arg line="shell am start"/> <arg line="${project.app.launcharg}"/> </exec> </target>
android.intent.category.LAUNCHER
in its intent filter of intentions - this is how Android defines activities that should be shown in the menu. There may be several of them (although this is rare), so the task takes the first one.AndroidManifest.xml
either by a record with the full name, or only by the name of a class with a dot in front, if the activity lies in the main package. At least that is what the documentation says . The only problem is that Eclipse and other tools allow the dot to drop and just write the name of the activity when it is in the main package. Android tolerates such connivance, but the team running the application is no longer there. We have to add a point when it is not enough. Here the task if
, recently mentioned by me, and regular expressions will help us.-pre-build
is called before all these actions begin, -pre-compile
just before the compilation of the project itself, -post-compile
- between compilation and packaging, -post-build
- after packaging, but before signing, and -post-build
is called at the very end. Well, when -pre-clean
is called, I think, is clear from the name.Source: https://habr.com/ru/post/207384/
All Articles