相关文章推荐
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Since today, somehow my ionic project is not longer able to build for some reason. I already tried to remove the platform and add it again, but it didn't work. I now almost spent three ours with upgrading, downgrading and reinstalling cordova and ionic but for some reason I always get the following error when I try to build the Android version:

Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
    java.lang.IllegalStateException: buildToolsVersion is not specified.
            at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
            at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.java:599)
            at com.android.build.gradle.BasePlugin$10$1.call(BasePlugin.java:566)
            at com.android.build.gradle.BasePlugin$10$1.call(BasePlugin.java:563)
            at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:55)
            at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:47)
            at com.android.build.gradle.BasePlugin$10.execute(BasePlugin.java:562)
            at com.android.build.gradle.BasePlugin$10.execute(BasePlugin.java:559)
            at org.gradle.listener.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:109)
            at org.gradle.listener.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:98)
            at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:83)
            at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:31)
            at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
            at com.sun.proxy.$Proxy12.afterEvaluate(Unknown Source)
            at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:79)
            at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:65)
            at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:504)
            at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:83)
            at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:42)
            at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
            at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129)
            at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
            at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
            at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
            at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
            at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
            at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
            at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
            at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
            at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
            at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
            at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
            at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
            at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
            at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
            at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
            at org.gradle.util.Swapper.swap(Swapper.java:38)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
            at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
            at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
            at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
            at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
            at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
            at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
            at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
            at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:46)
            at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
            at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)
    FAILURE: Build failed with an exception.

I already tried to set the buildToolsVersion in the config.xml but without any success. Did anyone have the same problem before?

I figured it out, the problem was due to a misconfigured config.xml entry:

<widget xmlns="http://www.w3.org/ns/widgets"
        xmlns:cdv="http://cordova.apache.org/ns/1.0"
        id="ch.papers.test"
        version="1.0.{BUILD_NUMBER}"
        android-versionCode="{BUILD_NUMBER}">...

Which we use for our Jenkins configuration. Unfortunately the error message was quite confusing.

Update corrected version:

<widget xmlns="http://www.w3.org/ns/widgets"
        xmlns:cdv="http://cordova.apache.org/ns/1.0"
        id="ch.papers.test"
        version="1.0.0"
        android-versionCode="1">...
                I am getting an error which is exactly same as yours, but I checked my config.xml file, it does not contain anything like your case. Could you please explain your solve a bit more?
– orchidrudra
                Apr 20, 2016 at 11:25
                I acutually solved the problem by changing these two lines of code:  version="1.0.{BUILD_NUMBER}" android-versionCode="{BUILD_NUMBER}"  to  version="1.0.0" android-versionCode="1"
– Lukas
                Apr 23, 2016 at 11:56
                In my case, I was using linux command sed to replace a string with Jenkins' BUILD_NUMBER but it wasn't working. The problem was that I was using single quote ' instead of double quotes " in the sed parameter, something like this worked for me: sed -i "s/CODE_VERSION/${BUILD_NUMBER}/g" config.xml
– Pedro Madrid
                Oct 24, 2016 at 20:17
                This should be located in your project root. But be aware, this is not a standard Android projects, it's a ionic / cordova project.
– Lukas
                Dec 6, 2016 at 0:57

I was facing this issue. The problem was that my ANDROID_HOME path was pointing to Android Studio's folder. I changed it to point to my Android SDK Folder and problem was solved.

  • Check your ANDROID_HOME:
  • echo $ANDROID_HOME

  • It should point to the Android SDK Folder:
  • export ANDROID_HOME="your-android-sdk-folder"

    Open Android studio configuration.

    Go to config>SDK Manager>Android SDK>SDK Tools and install Android SDK Build-Tools.

    Check the ANDROID_HOME variable. I am on mac, so it points to "/Users/user_name/Library/Android/sdk/"

    If not set correctly set it as follows:-

    export ANDROID_HOME="/Users/user_name/Library/Android/sdk/"

    Now build it again and it should work fine.

    PS:Getting android sdk by installing Android Studio is highly recommended than installing the sdk manually. This way you will not run into unnecessary trouble.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

     
    推荐文章