how to import googlesource projects in to Android Studio? - android-studio

I'm new to Gradle and Android Studio and I've been struggling to import any of the projects under https://android.googlesource.com/platform/packages/apps/ in to AS and successfully run it on my dev device. I'm trying to get the Launcher3 running and I get all kinds of different errors. I think I'm missing some major parts on how to configure the studio and Gradle maybe?
What is the proper procedure?
I installed Latest Gradle and AS. Cloned the project from Git. Imported to AS and then I get errors like this or that version of Gradle is required, main activity cant be found, gradle plugin can't be found etc. Tried changing Gradle version in config file. Tried setting my local Gradle download in build settings etc.
Cheers,
Hamed
Update:
I changed the version to 2.1.2 here:
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.protobuf:protobuf-gradle-plugin:2.1.2'
}
and currently I get the error:
Error:Could not find com.google.protobuf:protobuf-gradle-plugin:2.1.2.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/protobuf/protobuf-gradle-plugin/2.1.2/protobuf-gradle-plugin-2.1.2.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/protobuf/protobuf-gradle-plugin/2.1.2/protobuf-gradle-plugin-2.1.2.jar
https://repo1.maven.org/maven2/com/google/protobuf/protobuf-gradle-plugin/2.1.2/protobuf-gradle-plugin-2.1.2.pom
https://repo1.maven.org/maven2/com/google/protobuf/protobuf-gradle-plugin/2.1.2/protobuf-gradle-plugin-2.1.2.jar
Required by:
:Launcher3:unspecified

I think you might have confused the build tools version for the protobuf-gradle-plugin version.
The latest protobuf-gradle-plugin version is 0.8.2, as seen here.
try changing it to:
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.2'

Related

Problem with build Gradle 7.2 , still writtencolud not find Gradle 6.1.1

I just downloaded gradle6.1.1 to my android studio ,every time i build any project i get the following: Could not find com.android.tools.build:gradle:6.1.1.
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/6.1.1/gradle-6.1.1.pom
https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/6.1.1/gradle-6.1.1.pom
Required by:
project :capacitor-app
Add google Maven repository and sync project
Open File
is there a way anyone can help me… or may be tell me where to save gradle-6.1.1.pom on my device.
Thank you
build.gradle file must be like that
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
gradle-wrapper.properties file must be like that
distributionUrl=https://services.gradle.org/distributions/gradle-7.4.2-all.zip

Ionic Capacitor app give me lots of errors

I'm on Windows 10 and I've created a Ionic 5.0.7 app with Capacitor 2.0.0.
I use this command to build app:
ionic build
After, I use this command:
npx cap sync
And, to finish, I use this command to open Android Studio:
npx cap open android
The first problem come during building on Android Studio:
org.gradle.api.reflect.ObjectInstantiationException: Could not create
an instance of type
com.novoda.release.internal.compat.gradle5_3.AndroidSoftwareComponentCompat_Gradle_5_3.
Caused by: org.gradle.api.reflect.ObjectInstantiationException: Could not create
an instance of type
com.novoda.release.internal.compat.gradle5_3.AndroidSoftwareComponentCompat_Gradle_5_3.
And...
java.lang.NoClassDefFoundError:
org/gradle/api/internal/java/usagecontext/LazyConfigurationUsageContext
Caused by: java.lang.NoClassDefFoundError:
org/gradle/api/internal/java/usagecontext/LazyConfigurationUsageContext
I've other random errors... It's weird...
Update
Check #Carl Pool 's answer
They fixed it in the new capacitor Version, no need to downgrade anymore
Old Answer
To fix this downgrade Gradle and Gradle plugin in Android Studio.
File -> Project Structure -> Project
If you keep the plugin to 4.0.0 it will require a minimum Gradle version of 6 so put it back to a lower version like 3.6.3
Version 6 of Gradle does not support LazyConfigurationUsageContext as mentionened by #NishaBhat, so use 5.6.4 instead.
This issue currently has a ticket on Github:
https://github.com/ionic-team/capacitor/issues/3003
This issue has been resolved in Capacitor version 2.1.2.
https://github.com/ionic-team/capacitor/issues/3003
Please update the Capacitor dependencies in package.json to version 2.1.2 and then in Android Studio click the button to sync the project with Gradle.
"#capacitor/android": "^2.1.2",
"#capacitor/core": "2.1.2",
Switch to using gradle version 5.6.4. That did the trick for me. LazyConfigurationUsageContext doesn't have support in gradle versions 6.0+
I was getting an error
Cause: org/gradle/api/internal/java/usagecontext/LazyConfigurationUsageContext
I solved by downgraded distributionUrl(gradle/wrapper/gradle-wrapper.properties) to https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
it will give an error if above 6+
Same problem.. had many issues:
Errors and how I solved:
Error 1. Gradle sync failed: Server returned HTTP response code: 403 for URL: http://services.gradle.org/distributions/gradle-5.6.4-all.zip
Solution - Downloaded the zip file and stored in on my local in the \android\gradle\wrapper folder.
Updated the distribution URL to: distributionUrl=./gradle-5.6.4-all.zip
Error 2. java.lang.NoClassDefFoundError & java.lang.NoClassDefFoundError:
Solution - Downloaded Gradle version 5.6.4 and updated the environment variables.
Error 3. Failed to install the following Android SDK packages as some licences have not been accepted.
build-tools;28.0.3 Android SDK Build-Tools 28.0.3
Updated as per the image below
i have not downgraded the gradle version 6.1.1 But what i did is that:
I removed these lines from build.gradle file
apply plugin: 'com.novoda.bintray-release' &
classpath 'com.novoda:bintray-release:0.9.1'
The Issue just gone like Boom !!
I think this Bintray Dependencies just conflicting behind the scene.

Where is build:gradle:2.1.0-alpha3?

I have Just installed Android Studio Version 2.1 Preview 3 (AI-143.2682553)
When I run my project I get an error, it says:
Could not find com.android.tools.build:gradle:2.1.0-alpha3.
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/build/gradle/2.1.0-alpha3/gradle-2.1.0-alpha3.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/2.1.0-alpha3/gradle-2.1.0-alpha3.jar
When I look in the Jcenter repository it only has 2.1.0-alpha1 https://jcenter.bintray.com/com/android/tools/build/gradle/
So I get why it can't find alpha3, but when I change the build.gradle to 2.1.0-alpha1 it says:
"The projects is using an incompatible version of the android Gradle plugin.
To continue opening the project, the IDE will update the Android Gradle plugin to version 2.1.0-alpha3"
which doesn't seem to exist right ?
Android Plugin for Gradle version 1.5.0 does not support Instant Run. Please update to version 2.1.0-alpha3
I had the similar problem and I fixed it by update it in android studio,just like this!
after update ,I find out the changes of gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0-alpha3'
// classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
buildToolsVersion '24 rc1'//buildToolsVersion "23.0.2"
I had the similar issue with 2.1.0-alpha3 .. my project cannot be complied ..I used earlier version 2.1.0-alpha1 # http://tools.android.com/download/studio/builds/android-studio-2-1-preview-1
By uninstalling and installing older version.
Hope that may help.

Android Studio - Gradle sync error on gradle-diagnostics-X.X.X.jar

I've just updated Android Studio and I can't sync my project anymore.
The event log reports:
Gradle sync failed: /Applications/Android Studio.app/Contents/gradle/gradle-X.X.X/lib/plugins/gradle-diagnostics-X.X.X.jar (No such file or directory)
To solve the Gradle sync error, open gradle-wrapper.properties file and update the Gradle wrapper distribution version from:
distributionUrl=https\://services.gradle.org/distributions/gradle-X.X.X-all.zip
To:
Android Studio 3.4
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Android Studio 2.3 distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-all.zip
Android Studio 2.2 distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Android Studio 2.1 distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
Android Studio 2.0 distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
Android Studio 1.5 distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Android Studio 1.3 distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
You can find the latest Gradle wrapper version visiting:
https://services.gradle.org/distributions/
EDIT:
As a side note, as #SeBsZ suggests,
the official repository of the Android Gradle plugin switched from MavenCentral to jCenter (see Bintray blog post).
Make sure your project build.gradle file contains the new repository and the new classpath:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
This is not strictly related to the question problem, but since we are already migrating to the new IDE preview it's better to make sure everything is in place.
If, like me, you are using an older project then you might still be using the maven repository. Make sure you change the repositories in your top-level build.gradle from maven() to jcenter(). Then make sure you are using the correct dependency as well: classpath 'com.android.tools.build:gradle:1.3.0-beta1' for the new 1.3 preview.
For me helped to set chmod on the .gradle directory to 777. After this whole Android studio started working correctly.
I got the same issue after updating android studio to 3.4
I resolve this updatig gradle-wrapper.properties
I had
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
I leave
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
and with this To solve the Gradle sync error.
This is the weirdest thing ever and I never expected it to work but this:
distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip
worked and got everything fixed (it was the '\' after https). It does make sense since that is an actual link to a file.
check your .bash_profile file and make sure your GRADLE_HOME points to a valid path, if things were working and you face this issue after android studio update, chances are your gradle got updated too.
Here is the example of my gradle home in .bash_profile:
export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-2.14.1/bin
Had the same problem with a newly set up Android Studio 2.2.2, gradle wrapper 2.14.1. I loaded the project before i installed the needed android-23 library and installed java after Android Studio installation.
Error message in Android Studio 2.2.2:
Error:The specified Gradle distribution
'https://services.gradle.org/distributions/gradle-2.14.1-all.zip' does
not appear to contain a Gradle distribution.
Error message in cmd:
projectfolder> gradlew
Exception in thread "main" java.lang.NullPointerException
at org.gradle.wrapper.BootstrapMainStarter.findLauncherJar(BootstrapMainStarter.java:34)
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:25)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
When i used gradle from cmd however it worked
projectfolder> set PATH=%PATH%;C:\AndroidStudio2.0\gradle\gradle-2.14.1\bin\
projectfolder> set GRADLE_HOME=C:\AndroidStudio2.0\gradle\gradle-2.14.1\bin\
projectfolder> cd C:\projectfolder\
projectfolder> gradle
BUILD SUCCESSFUL
In cmd i see that the gradle versions and android sdk version were correct
C:\>set | find "JAVA_HOME"
JAVA_HOME=C:\Java\jdk1.8.0_111\
However in C:\Users\.AndroidStudio2.2\system\log\idea.log it said something else:
2016-11-29 16:04:10,597 [ 107684] INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/AndroidStudio2.0/jre
2016-11-29 16:04:10,597 [ 107684] INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/AndroidStudio2.0/jre
After messing up Android Studio config files i ended up reinstalling everything in correct order (Java, Android Studio, Project) and it worked.
I got the same issue after updating my android studio to 1.5
Here is my error stack trace.
Error:A problem occurred configuring root project 'Kargo'.
java.io.FileNotFoundException: /home/adiyatmubarak/Documents/android-studio/gradle/gradle-2.4/lib/plugins/gradle-diagnostics-2.4.jar (No such file or directory)
After I checked to the android studio instalation directory within gradle, my gradle was gradle-2.8 I don't know how to setup my android studio path location, but for temporary fix I just rename it to gradle-2.4 and my problem solved.

Android studio preview 0.4.5: The project is using an unsupported version of the Android Gradle plug-in

I got the following error message when I was importing a project from github:
Failed to refresh Gradle project 'XXX'
The project is using an unsupported version of the Android Gradle plug-in.
Fix plug-in version and re-import project
This is not a duplicate of this because your get thee error message before
gradle/wrapper/gradle-wrapper.properties
is generated.
The problem appeared after updates. The updated Android Gradle plug-in did not support the outdated version of Gradle I had. But the error message is misleading, if you don't attempt different build options you won't see what the problem is.
After downloading a newer version of Gradle, Imported the project again, then:
Use local gradle distribution
Then Gradle home set to the folder where the new version of gradle was downloaded
that solved it
Edit: From Scott (below comments) : It's preferable to use the wrapper and to change the Gradle version in gradle-wrapper.properties instead of downloading and installing Gradle yourself. As for the Android-Gradle plugin, that's set in the dependencies.classpath block in your build file; see this
I get this gradle-errors in 4 Studio updates! My solution: I copy the Studio-folder, and if gralde throws an error, I copy the old version back. It's not a good way, but until google is not able to deliver an update without producing always the same errors (even if mentioned in many forums), I stay on 4.9 and wait for the first final release.

Resources