react-native run-android error "Task :app:javaPreCompileDebug FAILED" - java

EDIT: This issue was solved by forcing the gradle not to jetify my native library. This is done by adding in gradle.properties
android.jetifier.blacklist = your-causing-issues-library
For more details you can read the official docs or this post
I need to use some native code in a react native project. The native code is provided in a .jar file by the hardware manufacturer. In a clean project (react-native init), with this .jar file inside /android/app/libs folder, this error shows as soon as I try to run "react native run-android".
==============
Error is as follow:
Task :app:javaPreCompileDebug FAILED
6 actionable tasks: 6 executed
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:javaPreCompileDebug'.
Could not resolve all files for configuration
':app:debugCompileClasspath'.
Failed to transform file 'iMagPayV5.1.4.jar' to match attributes {artifactType=android-classes, org.gradle.usage=java-runtime-jars}
Execution failed for JetifyTransform:
/home/buonapasta/Desktop/React-Native/samples/project/android/app/libs/iMagPayV5.1.4.jar.
Failed to transform '/home/buonapasta/Desktop/React-Native/samples/project/android/app/libs/iMagPayV5.1.4.jar' using Jetifier. Reason: 10. (Run with --stacktrace for more details.)
==============
Help is appreciated in advance!!
(Sorry if some information is incomplete).
React Native version 0.60.4 running on Ubuntu 18.04.
I've tried to include some other .jar files in a clean project without inconvenience, but as soon as I include this particular .jar everything blows.
Also, this library is working on an Android Studio project.
The .jar can be found on
https://github.com/GPaoloni/imagpay-framework
android/app/build.gradle looks like this:
...
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
if (enableHermes) {
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
android/build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
}
}
I just want being able to include the .jar library (to be used by a native activity).
==============
Update:
I've tried doing like sugested:
npm install --save-dev jetifier
npx jetify
But the error still the same.
Reading the npm page of jetifier, in the "Usage for jar/zip/aar files" section:
npm install jetifier
npx jetifier-standalone <your arguments here>
Runing this gives me the following error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at org.objectweb.asm.ClassReader.readFrameType(ClassReader.java:2313)
at org.objectweb.asm.ClassReader.readFrame(ClassReader.java:2269)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1448)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
at com.android.tools.build.jetifier.processor.transform.bytecode.ByteCodeTransformer.runTransform(ByteCodeTransformer.kt:39)
at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:443)
at com.android.tools.build.jetifier.processor.archive.ArchiveFile.accept(ArchiveFile.kt:49)
at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:425)
at com.android.tools.build.jetifier.processor.archive.Archive.accept(Archive.kt:76)
at com.android.tools.build.jetifier.processor.Processor.transformLibrary(Processor.kt:421)
at com.android.tools.build.jetifier.processor.Processor.transform(Processor.kt:247)
at com.android.tools.build.jetifier.processor.Processor.transform$default(Processor.kt:234)
at com.android.tools.build.jetifier.standalone.Main.run(Main.kt:157)
at com.android.tools.build.jetifier.standalone.Main$Companion.main(Main.kt:109)
at com.android.tools.build.jetifier.standalone.Main.main(Main.kt)

Try executing these line by line.
1. yarn
2. yarn start
On a new terminal tab
1. react-native run-android
Check whether 'jetifier' running output is displayed on the terminal.
Something similar to this.
"Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag."
If not run these before executing 'react-native run-android'
1. npm install --save-dev jetifier
2. npx jetify

I am using VS Code and installed prettier and format on-save. For some reason, when I saved page, he formatted wrong and I had this error, when discarded changes, it started working well, u can try this, as prevention.

Related

Classes are being created without packages in Netbeans

everytime that I try to use LibGDX and netbeans I am struggling to just to get started.
create class
class created
I am not sure if the photos are going to be visible since I just created my account and my reputation is low but let me explain myself in case they will not.
So I created another project using LibGDX this is the result I got:
Executing 'C:\.....\ProTest/gradlew.bat clean --no-daemon' To honour
> the JVM settings for this build a new JVM will be forked. Please
> consider using the daemon:
> https://docs.gradle.org/6.7.1/userguide/gradle_daemon.html. Daemon
> will be stopped at the end of the build stopping after processing
> > Task :android:clean UP-TO-DATE
> > Task :core:clean UP-TO-DATE
> > Task :desktop:clean UP-TO-DATE
> > Task :html:clean
> > Task :ios:clean UP-TO-DATE Warning: Failed to parse host SSTap Warning: Failed to parse host SSTap Deprecated Gradle features were
> used in this build, making it incompatible with Gradle 7.0. Use
> '--warning-mode all' to show the individual deprecation warnings. See
> https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings
> BUILD SUCCESSFUL in 21s 5 actionable tasks: 1 executed, 4 up-to-date
> Done! To import in Eclipse: File -> Import -> Gradle -> Existing
> Gradle Project To import to Intellij IDEA: File -> Open ->
> build.gradle To import to NetBeans: File -> Open Project...
After that I opened Netbeans and Opened the project, trustgradle execution...
And I opened core, desktop and IOs without any problem from the subprojects created.
I went to the desktop project and inside has a class called "DesktopLauncher"
the code inside is
> package com.supa.testa.desktop; import
> com.badlogic.gdx.backends.lwjgl.LwjglApplication; import
> com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; public
> class DesktopLauncher { public static void main (String[] arg) {
> LwjglApplicationConfiguration config = new
> LwjglApplicationConfiguration(); new LwjglApplication(new Testo (),
> config); } }
and I created a class in the path "com.supa.testa" but it was created without mentioned the package on the top, I thought that by using extends Game will be fixed somehow as I cannot find the error and even write down the package path by myself... the code for the class "Testo" now looks like this:
package com.supa.testa;
import com.badlogic.gdx.Game;
public class Testo extends Game{
#Override
public void create() {
}
}
So I cameb back to the DesktopLauncher class and tried to create a class by using the "bulb" I dont know the name (help me with that please) and another class with the same name "Testo" was created in another path but again without the package on the top and it implemented the ApplicaitonListener by itself
import com.badlogic.gdx.ApplicationListener;
public class Testo implements ApplicationListener {
public Testo() {
}
}
then I came back to DesktopLauncher did the same and I could be doing that over and over again
it will go as "Testo_1" "Testo_2" and the class will never have a package and it will never be recognized
I tried to build and clean the project from the desktop, the core, the project itself, clean, build separately
Open and closed netbeans
create different projects (this was the last one)
The last thing I have tried, I pressed "Ctrl + Space bar" after the code:
new LwjglApplication(new .....
and the classes that appear are from other projects
When I created a project with LibGDX I am having this issue randomly
But now I can't get rid of it haha
I am not sure if its related with the Daemon
And in another of the tests I did the "LwjglApplicationConfiguration" library from badlogicgames seems like did not loaded because I was unable to use, did not appear at all, even after writing it manually it will not work (same as for the packages :( )
Have a nice day :D
Reedit:
I tried to create another project the previous was using Desktop, Android, IOs and Html
I tried only with desktop and the packages are working properly
I tried with Desktop and Html and this is what I got
Generating app in C:......
Executing 'C:\........ setup\ProTestD__H/gradlew.bat clean --no-daemon'
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/6.7.1/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'ProTestD__H'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not download commons-logging-1.1.1.jar (commons-logging:commons-logging:1.1.1)
> Could not get resource 'https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.
> Could not HEAD 'https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.
> SSTap
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 13s
Done!
To import in Eclipse: File -> Import -> Gradle -> Existing Gradle Project
To import to Intellij IDEA: File -> Open -> build.gradle
To import to NetBeans: File -> Open Project...
After that I opened the project to try to:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
In the Run gradle "--stacktrace":
enter image description here
enter image description here
enter image description here
enter image description here
and the code still going Im not sure if the photos will be uploaded and it is a lot so I cannot copy paste it here, I will try to past what I think is important
FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring root project 'ProTestD__H'.
Could not resolve all artifacts for configuration ':classpath'.
Could not download commons-logging-1.1.1.jar (commons-logging:commons-logging:1.1.1)
> Could not get resource 'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.
> Could not HEAD 'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.
> SSTap
Try: Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Exception is: org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'ProTestD__H'. at
org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
Caused by:
org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException:
Could not resolve all artifacts for configuration ':classpath'.
Caused by: org.gradle.internal.resolve.ArtifactResolveException: Could
not download commons-logging-1.1.1.jar
(commons-logging:commons-logging:1.1.1)
Caused by: org.gradle.api.resources.ResourceException: Could not get
resource
'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.
Caused by:
org.gradle.internal.resource.transport.http.HttpRequestException:
Could not HEAD
'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.
Caused by: java.net.UnknownHostException: SSTap
Using "--info" got:
FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring root project 'ProTestD__H'.
Could not resolve all artifacts for configuration ':classpath'.
Could not download commons-logging-1.1.1.jar (commons-logging:commons-logging:1.1.1)
> Could not get resource 'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.
> Could not HEAD 'ttps://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.
> SSTap
Try: Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.
Using "--scan" got this:
.\gradlew.bat --configure-on-demand -w --scan -x check
FAILURE: Build failed with an exception.
Where: Auto-applied by using --scan
What went wrong: Plugin [id: 'com.gradle.enterprise', version: '3.4.1', artifact: 'com.gradle:gradle-enterprise-gradle-plugin:3.4.1']
was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'com.gradle:gradle-enterprise-gradle-plugin:3.4.1') Searched in the
following repositories:
Gradle Central Plugin Repository
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at ttps://help.gradle.org
BUILD FAILED in 2s
And i got this when trying to resolve and trust the project
SSTap<br/>Could not HEAD 'https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.<br/>Could not get resource 'https://repo.maven.apache.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'.<br/>Could not download commons-logging-1.1.1.jar (commons-logging:commons-logging:1.1.1)<br/>Could not resolve all artifacts for configuration ':classpath'.<br/>A problem occurred configuring root project 'ProTestD__H'.<br/>A problem occurred configuring root project 'ProTestD__H'.<br/>Could not run build action using connection to Gradle installation 'C:\......\.gradle\wrapper\dists\gradle-6.7.1-bin\bwlcbys1h7rz3272sye1xwiv6\gradle-6.7.1'.
I also tried to follow the tutorials in LibGDX tutorials LibGDX tutorials
When trying to run the project in android by using the desktop folder
I got the "Warning: Class 'com.my.game.desktop.DesktopLauncher' not found in module 'Test'" I applied, tried to run and got:
Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-6.7.1-bin.zip'.
This is my build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
google()
}
dependencies {
classpath 'org.wisepersist:gwt-gradle-plugin:1.0.13'
classpath 'org.gretty:gretty:3.0.2'
classpath 'com.android.tools.build:gradle:3.5.4'
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.12'
} }
allprojects {
apply plugin: "eclipse"
version = '1.0'
ext {
appName = "Kiya"
gdxVersion = '1.10.0'
roboVMVersion = '2.3.12'
box2DLightsVersion = '1.5'
ashleyVersion = '1.7.3'
aiVersion = '1.8.2'
gdxControllersVersion = '2.1.0'
}
repositories {
mavenLocal()
mavenCentral()
google()
gradlePluginPortal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
} }
project(":desktop") {
apply plugin: "java-library"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
} }
project(":android") {
apply plugin: "com.android.application"
configurations { natives }
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
} }
project(":ios") {
apply plugin: "java-library"
apply plugin: "robovm"
dependencies {
implementation project(":core")
api "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
api "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
api "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios"
} }
project(":html") {
apply plugin: "java-library"
apply plugin: "gwt"
apply plugin: "war"
apply plugin: "org.gretty"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
api "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion:sources"
api "com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources"
} }
project(":core") {
apply plugin: "java-library"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
} }
Not sure if I understood the question correctly, but if your problem is, that the DesctopLauncher doesn't know the class Testo you just need to import it: import com.supa.testa.Testo
Also you should place your Game classes (and packages) like Testo in the core project, since it will be used in all projects (desctop and ios).
You should have a look at the libGDX tutorials.
Especially Setup and Hello World should contain what you are searching for.
I have this other post... Removing the proxy and host from Netbeans I just fixed it.... and even tho the packages are stillnot visible in core or desktop project, if I create a class in core and put some code in it and run it from Desktoplauncher it works even tho it shows an error cannot find symbol(class), but the projects runs perfectly... for now O_O
The classes are still created without package and if the package is created(typed) by myself it shows error but now it works. Even if it is a project that uses ScreenAdapter
This is what I did....
I went into my gradle.properties file found in C:\Users\User. gradle inside looks like this:
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Sat Dec 25 18:51:22 CST 2021
systemProp.http.proxyHost=SSTap
systemProp.https.proxyHost=SSTap
systemProp.https.proxyPort=25378
systemProp.http.proxyPort=25378
systemProp.https.nonProxyHosts=127.0.0.1
systemProp.http.nonProxyHosts=127.0.0.1
I removed the last 6 rows,created a new project using Desktop, Android, IOs, HTML in LibGDX , trusted all the projects with gradle, classes have no packages when created, if I create them or import them by myself (in desktop project). And even if it says "cannot find symbol"(class) within the core path e.g. import com.pokedemon.game.Hello; the code runs

Android Studio `Plugin with id 'com.android.application' not found` [duplicate]

This is my first attempt at Android Studio. I installed 0.8.0 and updated to 0.8.2. As soon as a project is created I get the error message:
Error:(1, 0) Plugin with id 'com.android.application' not found
C:\Users\Bob\AndroidStudioProjects\HelloAgain6\app\build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.bob.helloagain6"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
and C:\Users\Bob\AndroidStudioProjects\HelloAgain6\build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Updated Answer (Dec. 2, 2020)
Latest Gradle: 6.5
Version check:
./gradlew -v
How to update:
Set URL: ./gradlew wrapper --gradle-version=6.5 --distribution-type=all
Update: ./gradlew wrapper
Latest Android Gradle Plugin: 4.1.0
If you add the following code snippet to the top of your build.gradle file. Gradle will update the build tools.
buildscript {
repositories {
google() // For Gradle 4.0+
maven { url 'https://maven.google.com' } // For Gradle < 4.0
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
Read more here: https://developer.android.com/studio/build/index.html and about version compatibility here: https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle and https://dl.google.com/dl/android/maven2/index.html.
Original Answer
I had this same error, you need to make sure your Gradle version is compatible with your Android Gradle Plugin.
The latest version of Gradle is 2.0 but you need to use 1.12 in order to use the Android Gradle Plugin.
This can happen if you miss adding the Top-level build file.
Just add build.gradle to top level.
It should look like this
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.xx.y'
}
}
allprojects {
repositories {
mavenCentral()
}
}
In my case, I download the project from GitHub and the Gradle file was missing. So I just create a new project with success build. Then copy-paste the Gradle missing file. And re-build the project is working for me.
Root-gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:x.x.x'
}
}
allprojects {
repositories {
jcenter()
}
}
Gradle-wrapper.properties file:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-x.x-all.zip
In the project level build.gradle file, I have replaced this line
classpath 'com.android.tools.build:gradle:3.6.3'
with this one
classpath 'com.google.gms:google-services:4.3.3'
After adding both of those lines, and syncing, everything became fine.
Hope this will help someone.
I am writing this not as a solution meant for many, but for some people who may commit a simple mistake like specifying the wrong url for importing projects from SVN. It is intended for those guys :)
This happened to me when I imported the project from SVN -> automatic prompt by Studio to open the project -> It asked for Gradle location -> D:\Software\Android\gradle-2.5 -> Then the error.
The same project in a different SVN branch works fine with the Gradle plugin and Gradle which I have configured in Studio. I tried changing Android Gradle plugin and Gradle to get it working on the erring branch without any success.
Finally, I figured out that it was my following mistake:
I tried importing a specific Application alone instead of importing the application along with dependent library projects.
The url which I used for import initially had the Application porject's name at the end. Once I removed it, and specified the parent directory which contained both application project and its dependent project, everything went smooth :)
I found the problem after one hour struggling with this error message:
I accidentally renamed the root build.gradle to filename in builde.gradle, so Android Studio didn't recognize it anymore.
Renaming it to build.gradle resolved the issue!
I still got the error
Could not find com.android.tools.build:gradle:3.0.0.
Problem: jcenter() did not have the required libs
Solution: add google() as repo
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0"
}
}
I was using IntelliJ IDEA 13.1.5 and faced with the same problem after I changed versions of Picasso and Retrofit in dependencies in build.gradle file. I tried use many solutions, but without result.
Then I cloned my project from remote git (where I pushed it before changing versions of dependencies) and it worked! After that I just closed current project and imported old project from Gradle file to IntelliJ IDEA again and it worked too! So, I think it was strange bug in intersection of IDEA, Gradle and Android plugin. I hope this information can be useful for IDEA-users or anyone else.
Go to your grade file where you can see this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
And change classpath to this:
buildscript {
repositories {
jcenter()
}
dependencies {
// classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle-experimental:0.7.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
The other answers didn't work for me, I guess something wrong happens between ButterKnife and 3.0.0 alpha5.
However, I found that when I annotated any one sentence, either BUtterKnife or 3.0.0 alpha5, it works normally.
So, you should just avoid the duplication or conflict.
For future reference: For me, this issue was solely caused by the fact that I wasn't running Android Studio as administrator. I had the shortcut on Windows configured to always run as administrator, but after reinstalling Android Studio, the shortcut was replaced, and so it ran without administrator rights. This caused a lot of opaque errors, including the one in this question.
This issue happened when I accidently renamed the line
apply plugin: 'com.android.application'
on file app/build.gradle to some other name. So, I fixed it by changing it to what it was.
[FOR FLUTTER] go to your build Gradle then check if you have three paths
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
I somehow removed the android tools classpath and was getting the error.
This just happened to me using Android Studio 1.3.2, however, since I had just created the project, I deleted it and created it again.
It seems that it had not been properly created by Android Studio the first time, not even the project folders where as expected.
If you run a the module task with android plugin 1.2.3 in module directory , the problem appears. Try this:
../gradlew -b ../build.gradle -c ../settings.gradle :module:xxx
Make sure your two build.gradle and settings.gradle files are in the correct directories as stated in https://developer.android.com/studio/build/index.html
Then open "as existing project" in Visual Studio
Gradle is very finicky about this.
I got this error message after making the following change in my top-level build.gradle to update to the latest version of gradle:
//classpath 'com.android.tools.build:gradle:2.3.2' old
classpath 'com.android.tools.build:gradle:2.3.3' //new
I foolishly made the change while I was connected behind a hostile workplace proxy. The proxy caused the .jar files for the new version of gradle to become corrupt. This can be verified by inspecting the jars to see if they are an unusual size or whether they can be unzipped.
In order to fix the mistake, I connected to my network at home (which is not behind a proxy) and did a refresh dependencies from the Terminal:
./gradlew --refresh-dependencies
This caused the newer version of gradle to be re-downloaded and the error no longer occurs.
Check the spelling, mine was 'com.android.aplication'
This may also happen when you have both settings.gradle and settings.gradle.kts files are present in project root directory (possibly with the same module included). You should only have one of these files.
i had similar problem and i did following things to resolve it.
i referred to https://developer.android.com/studio/build
and copy / pasted these following lines before apply plugin lines
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
}
}
module app build.gradle file
apply plugin: 'com.android.application'
model{
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig.with {
applicationId "com.iamsafe"
minSdkVersion 15
targetSdkVersion 23
}
buildTypes {
debug {
minifyEnabled = false
useProguard = true
proguardFiles.add(file('proguard-rules.txt'))
}
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.0.2'
compile files('libs/asmack-android-8-0.8.10.jar')
compile files('libs/commons-io-2.0.1.jar')
compile files('libs/httpclient-osgi-4.2.1-sources.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.1.2.jar')
}
project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.10'
}
}
allprojects {
repositories {
jcenter()
}
}
In this case of issues check below code
dependencies {
classpath 'com.android.tools.build:gradle:**1.5.0**'
}
and gradle-wrapper.properties inside your project directory check below disctributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip
If these are not compatible with each other then you end up in this issue.
For com.android.tools.build:gradle:1.5. you need a version at least 2.8 but if you switch to a higher version like com.android.tools.build:gradle:2.1.0 then you need to update your gradle to 2.9 and above this can be done by changing distributionUrl in gradle-wrapper.properties to 2.9 or higher as below
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
If you work on Windows , you must start Android Studio name by Administrator.
It solved my problem
Just make sure you put the http and https proxy correctly when you create the app

gradle project sync failed even after upgrading gradle plugin

Gradle project sync failed and did not get answers from other related questions. Here are the details of my situation.
Initial sync attempt yielded the following error message:
Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
I have Android Studio 3.0. The build.gradle file includes the following dependency:
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
The gradle-wrapper.properties file includes the following distribution URL:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
According to https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#update_gradle I need to make some changes.
First, update the Gradle version for Android Studio 3.0 in gradle-wrapper.properties:
distributionUrl=\
  https://services.gradle.org/distributions/gradle-4.1-all.zip
(I believe the backslash right after the equal sign is an error and did not make that change.)
Second, add the following buildscript repository to build.gradle:
google()
Third, change the build.gradle dependency:
classpath 'com.android.tools.build:gradle:3.0.1'
The second and third changes apply the latest version of the Android plug-in.
When I try to sync after these changes it fails again with the following new error:
Plugin with id 'com.android.model.application' not found.
The error refers to the first line of build.gradle:
apply plugin: 'com.android.model.application'
What is happening and why? I recently added NDK to Android Studio. The project I'm trying to sync includes C code. I'm not completely certain I added NDK correctly. I wonder if that could be part of the problem.
First, the gradle-wrapper.properties is incorrect. You must include \ in it. It should be something like this:
#Sat Jun 17 17:47:18 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Then, add the experimental classpath to project build.gradle. Something like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle-experimental:0.7.0-alpha4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Check the Experimental Plugin User Guide for details.
Go to your build.gradle version or update it
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
You should change you dependencies classpath
All steps are here :
Open build.gradle and change the gradle version to the recommended version:
classpath 'com.android.tools.build:gradle:1.3.0' to
classpath 'com.android.tools.build:gradle:2.3.2'
Hit 'Try Again'
In the messages box it'll say 'Fix Gradle Wrapper and re-import project' Click that, since the minimum gradle version is 3.3
A new error will popup and say The SDK Build Tools revision (23.0.1) is too low for project ':app'. Minimum required is 25.0.0 - Hit Update Build Tools version and sync project
A window may popup that says Android Gradle Plugin Update recommended, just update from there.
Now the project should be runnable now on any of your android virtual devices.
Make sure your Gradle version is compatible with your Android Gradle Plugin.
https://stackoverflow.com/questions/24795079
https://developer.android.com/studio/releases/gradle-plugin#updating-gradle

Upgrading firebase-crash caused error building apk

I originally added firebase crash reporting using Android firebase assistant in android studio. Which added firebase-crash:10.0.1. Now i am want access some methods added in later version so i upgraded it to to firebase-crash:11.2.0.
This is where the problem starts
I used this guide to make changes in my gradle.build (Module:app)
Changed compile 'com.google.firebase:firebase-crash:10.0.1' to compile 'com.google.firebase:firebase-crash:11.2.0'
At this point gradle sync failed. To resolve this i modified build.gradle (Project) with
allprojects {
repositories {
jcenter()
//Added this code
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
Gradle build sync completed succesfully. Now i tried building debug apk and i received this error
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzbvb;
To fix this issue i modified buil.gradle(Modeule:app)
defaultConfig{
///...
multiDexEnabled true
///...
}
And now i am able to generate debug-build apk. But generating signed apk gives following error with 1588 warnings & 1 error.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
Job failed, see logs for details
This is where i am stuck. I am not able to resolve this issue. I tried several methods including clean/rebuild and invalidate cache & restart. Also tried adding -ignorewarning -dontwarn -keep class { public private} none of them seems to work.
Error in console on generating signed apk
build.gradle(Project)
build.gradle(Module:app)
Update
Adding this line compile 'com.google.android.gms:play-services:11.2.0 in build.gradle (Module:app) does build signed apk successfully. But shows following warnings.
I am confused
Using the Firebase version 11.2.0 (that has a dependency with Google play services v.11.2.0), you should use also the support libraries v26.
In your case:
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
Also you have to use:
compileSdkVersion 26
More info here.

Unable to run Gradle app engine tasks

I'm really confused about converting an old Google App Engine project to Gradle.
I'm trying to follow the instructions on this page. It advises to start with this build script:
buildscript { // Configuration for building
repositories {
jcenter() // Bintray's repository - a fast Maven Central mirror & more
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' // latest App Engine Gradle tasks
}
}
repositories { // repositories for Jar's you access in your code
maven {
url 'https://maven-central.storage.googleapis.com' // Google's mirror of Maven Central
// url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT Repository (if needed)
}
jcenter()
mavenCentral()
}
apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
dependencies {
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
compile 'com.google.appengine:appengine:+'
// Add your dependencies here.
}
appengine { // App Engine tasks configuration
run { // local (dev_appserver) configuration (standard environments only)
port = 8080 // default
}
deploy { // deploy configuration
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}
group = 'com.example.appengine' // Generated output GroupId
version = '1.0-SNAPSHOT' // Version in generated output
sourceCompatibility = 1.7 // App Engine Standard uses Java 7
targetCompatibility = 1.7 // App Engine Standard uses Java 7
However it doesn't work:
$ gradle appengineRun
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/myproject/build.gradle' line: 32
* What went wrong:
A problem occurred evaluating root project 'myproject'.
> Could not find method run() for arguments [build_c1i62diotjttavcmtjg1zqlbd$_run_closure3$_closure5#33f17289] on root project 'myproject' of type org.gradle.api.Project.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Shouldn't the dependencies be downloaded to make the custom appengine task configuration work?
Please have a look at the sources of the plugin. When the core plugin is applied it decides whether to apply a flexible or standard appengine plugin. Since there's probably no src/main/webapp/WEB-INF/appengine-web.xml flexible plugin is applied which does not create the extension that fails (FYI, this extension is created here). To fix the problem run:
mkdir -p src/main/webapp/WEB-INF
and then:
touch src/main/webapp/WEB-INF/appengine-web.xml
in console where build.gradle is located. This will solve the problem. Poor documentation :/

Categories

Resources