Home » Android » android – failed to create task or type checkenv Cause The name is undefined

android – failed to create task or type checkenv Cause The name is undefined

Posted by: admin June 15, 2020 Leave a comment

Questions:

I know there are some questions related to this but what Im trying to do is a bit different.

my 2 targets that I have specified in my project config options are

clean
debug

both of them are available by default so I dont have to write new code for any additional targets. but my build is still failed.

Started by user anonymous
[EnvInject] - Loading node environment variables.
Building in workspace /var/lib/jenkins/jenkins-data/jobs/anttest1/workspace
Checkout:workspace / /var/lib/jenkins/jenkins-data/jobs/anttest1/workspace - [email protected]
Using strategy: Default
Last Built Revision: Revision 17b9fd2ee52d01e7a425822f353222445e3a82c7 (EventMatrix_Cordova_App/HEAD, EventMatrix_Cordova_App/master)
Fetching changes from 1 remote Git repository
Fetching upstream changes from EventMatrix_Cordova_App
Seen branch in repository EventMatrix_Cordova_App/HEAD
Seen branch in repository EventMatrix_Cordova_App/master
Commencing build of Revision 17b9fd2ee52d01e7a425822f353222445e3a82c7 (EventMatrix_Cordova_App/HEAD, EventMatrix_Cordova_App/master)
Checking out Revision 17b9fd2ee52d01e7a425822f353222445e3a82c7 (EventMatrix_Cordova_App/HEAD, EventMatrix_Cordova_App/master)
Warning : There are multiple branch changesets here
[mysteryshopper_version2] $ ant -file build.xml -Dlabel=anttest1-42 clean
Buildfile: /var/lib/jenkins/jenkins-data/jobs/anttest1/workspace/mysteryshopper_version2/build.xml
  **[taskdef] Could not load definitions from resource anttasks.properties. It could not be found.
  [taskdef] Could not load definitions from resource emma_ant.properties. It could not be found.**

-**check-env**:

BUILD FAILED
/usr/local/lib/android-sdk-linux/tools/ant/build.xml:392: Problem: **failed to create task or type checkenv**
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.


Total time: 0 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE

can someone help me on this ??

How to&Answers:

<checkenv /> is required for the Android build, it’s in a library in the Android SDK directory. I had the same problem and discovered the cause was a bad directory in the local.properties file required by build.xml and buildAndroid.xml. Here’s a sample of my local.properties file:

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.

# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=/Users/myusername/android-sdk-macosx

This gets generated automatically when I’m in Eclipse, but when Eclipse is closed and I’m working with ant at the command line, it was not updated and had some other user’s information that had been committed to SVN and I checked out with an svn update.

I updated it to point to my own Android SDK directory and everything started working.

Hope that helps!

Answer:

The problem is not with anttasks.properties or emma_ant.properties(at least for me). I fixed it differently. My target build.xml had these lines

<property file="local.properties"/>
<property file="project.properties"/>
<property file="ant.properties"/>

Curiously enough, the local.properties was missing from the build.xml folder, whereas the other two were present. Luckily, I had already had it because of my previous attempt with Android Studio i.e. in StudioProjects/<my project>/local.properties. In other words it is automatically created by Android Studio. If you don’t have it, this is its content:

## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Fri Apr 22 21:28:15 EEST 2016
ndk.dir=home/<user>/android-ndk-r11c
sdk.dir=home/<user>/Android/Sdk

So, you basically can create it yourself specifying the paths of your SDK and possibly NDK.

I hope it helps.

Answer:

I had an antbuild running while updating the build tools resulting in a file access conflict 🙂 SDK Manager showed it as installed though. Deleting and re-installing fixed the problem.