Skip to content Skip to sidebar Skip to footer

Cannot Create New Activity In Android Studio

I keep getting an IllegalStateException error in the event log while creating new activity in android studio: 11:27:15 InvalidReferenceException: Error executing FreeMarker templat

Solution 1:

I've encountered the same problem and trying the following steps were working for me:

  1. close android studio
  2. delete folders: .idea and .gradle
  3. re-open project using android studio

Solution 2:

Method 1:Just Remove the following code from your app level build.gradle

debug {
            storeFile file('/Users/Razz/Documents/keys/keystore.jks')
            storePassword 'ABC@123'
            keyAlias 'key0'
            keyPassword 'ABC@123'
      }

Method 2: In case, if there are two packages together (kotlin and java)

I was facing the same problem as whenever I create new activity form the activity templates provided by the android studio. Nothing was happening even after Gradle sync completes successfull.

After a long item, I figure out that, java directory name inside my project changed into kotlin somehow. And I supposed Android Studio looking for the java package to create new Activity.

Then, to solve this issue, I follow the below steps:

  1. Closed Android Studio
  2. Went to the project location up to java directory as ../ProjectName/app/src/main/
  3. In this main directory, I had the kotlin directory instead of java. So, I just renamed it to java.
  4. Then opened the project with Android Studio, and that's all.
  5. I created new activity it easily created one as it works before.

Solution 3:

I have been faced that, after I setup my android environment.I already set up and configured everything, but this still occur.After searching a few mins, I found the problem in Logcat, enter image description here

Then, I know project is missing Build Tool version. You have to give which build tool version you will use to run for project. Go to >> Project Structure , ( Cmd + ; ) in mac. Choose Compile Sdk Version and Build Tools Version, enter image description hereAfter the gradle build, creating new activity from menu error has been fixed. I hope this will help for you.

Notes : Some of the projects from Github or bitbucket also missing Build Tools version when you cloned and run the project. These are the same errors and this approach can help to solve for them.

Solution 4:

Comment the code in build.gradle which creates folders in tmp directory and then create the Activity.

After successful creation of activity ,revert back the commented code in build.gradle (Co)

allprojects {
/*String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
    buildDir = "C:/tmp/${rootProject.name}/${project.name}"
}*/
repositories {
    jcenter()
}

}

Solution 5:

In the file build.gradle, add

buildDir = "C:/tmp/${rootProject.name}/${project.name}"

sychronize gradle then remove it and synchronize again. This worked for me.

allprojects {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
repositories {
    jcenter()
}

}

Post a Comment for "Cannot Create New Activity In Android Studio"