location gradle dependencies / android studio plugin, Android Studio 1.3 - android

Looking at my build.gradle file (module:app, modified from the FragmentBasics example code)
- where is the android plugin ('com.android.application')?
- Where are the dependencies (e.g. "com.android.support:support-v4:22.2.0")?
- are these in Maven Central Repository or local?
I'm asking because I've had to meddle with the file names to get this project to build (e.g. the first version of com.android.support:support-v4 I tried would not build with my target sdk) - so I'm guessing future changes may break my build (correct?) and would like to get in early here. Also, are there different names for the android plugin (e.g. older names) in example code around the place? Has the name of the plugin changed over time (again, just wondering if future name changes here might break my build)?
Thanks
My build.gradle file for reference:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "website.[...].FragmentBasics"
minSdkVersion 7
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.+'
compile "com.android.support:support-v4:22.2.0"
compile "com.android.support:appcompat-v7:22.2.0"
compile "com.android.support:support-annotations:22.2.0"
}

Android support library is not in maven center, it's in your android sdk.
Open Android SDK Manager, you can check it:

If you're using newer versions of Android Studio, Gradle will look for your dependencies in the JCenter repository rather than Maven Central. Basically JCenter is a superset of Maven Central, that encompasses many additional repositories and artifacts. Also, JCenter has a better performance than Maven Central.
If you don't update the versions of external dependencies, Gradle plugin and targetSdkVersion etc, your project will always be able to build.

Related

Error: gradle version 2.2 is required. Current version is 6.5.1

I am coding a Java project in Android studio 4.0.
This is my current Gradle version (6.5.1). (In gradle-wrapper.properties)
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
error said:
Studio gradle version 2.2 is required. Current version is 6.5.1.
Then I turn my gradle version into 2.2, and it gives me another error:
Support for builds using Gradle versions older than 2.6 was removed in tooling API version 5.0.
You are currently using Gradle version 2.2.
You should upgrade your Gradle build to use Gradle 2.6 or later.
I've tried everything to do and read questions and articles. But seeing no hopes.
I am new to android app design. Any advise will be appreciated!
update 1(build.gradle):
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.pcschool.map"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.android.gms:play-services:7.3.0'
}
Android Studio uses a plugin to support gradle. Each version of the plugin supports a range of gradle versions.
In your case it sounds like you have a recent version of Android Studio, running a recent version of the gradle plugin, supporting the latest versions of gradle.
Your project however requires an older gradle version. Since the gap is pretty big (6.5.x to 2.2) your current version of the plugin will not support this old gradle version. You would have to downgrade the plugin, but doing so you'd probably also have to downgrade Android Studio to support the old plugin version.
I highly suggest changing the version of gradle that your project depends on to something more recent. You'll definitely have to make some changes to your build script(s) since a lot of things have changed since 2.2, but it will be worth it in the long term. Android Studio might even encourage you to do that when you launch it. If not, you can do it under Project Structure in the File menu.
If you for some reason can't upgrade, you'll need to find an older version of Android Studio that supports a version of the gradle plugin that in turn supports gradle 2.2.
Maybe you can try to add these lines in your build.gradle:
buildscript {
repositories {
mavenCentral();
jcenter();
google();
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
And the newest gradle version can be fetched on https://developer.android.com/studio/releases/gradle-plugin

Porting from Eclipse and Upgrading Android Libraries

I have an Android application that we have been building in Eclipse for years, and I am finally porting it to Android Studio (I am new to Android Studio and Gradle, so forgive my ignorance). I have successfully ported it and the app is up and running in Android Studio, but now need to overcome a couple more obstacles:
I want to upgrade deprecated methods and also move to the latest versions of Support Library, Google Services and GSon (I guess I can live without upgrading GSon if need be).
To complicate matters, we have an Ant based build which takes the source code and generates numerous white label instances of application, with some pretty complex replacements. I plan on keeping that - I don't want to Gradle that just yet (and not sure Gradle could handle it?).
So, first it looks like my Gradle generated by the port has dependencies as follows:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.mydomain.myapp"
minSdkVersion 14
targetSdkVersion 23
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.android.gms:play-services:+'
[....other dependencies that don't matter here....]
}
My question is : do I still need to have the upgraded versions of these libs here or is this done via a Gradle addition for running out Android Studio? And if not by lib dependencies as listed, how can I have the Ant build pick these upgrades once I make them? I do have a further complexity in that I think the generated source code structure is different than Eclipse, but I think I can adjust the Ant build accordingly.
I have read these, and while helpful really don't quite answer my question:
Android white labeling
and
Android App White Labeling
Thanks!
UPDATE
So after a LOT of playing around I finally have upgraded modules and libraries and it apparently (I need to do a lot of testing) is working. Not sure if this will save anyone anytime in the future, but the key seems to be:
Match the compileSdkVersion and buildToolsVersion versions.
Match the com.android.support:support and compile and tools versions, as closely as possible.
For the Support lib, choose the version just below your minSDK version (in my case it is 14, so I chose v13). I might have it wrong there but that is what got it working for me.
Be careful in which modules and which version of the modules you bring in, and that they are compatible. The tool did a decent job of warning, but if you are bring in the entire play services I would recommend pulling in the pieces since that was where my incompatibilities were coming from. Here is what it looks like now:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId "com.mydomain.myapp"
minSdkVersion 14
targetSdkVersion 23
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.android.support:support-v13:25.3.1'
compile 'com.google.code.gson:gson:2.7'
}
For anyone who finds the whole support library to be confusing and a mess (why would anyone think that?) this blog was very helpful:
http://martiancraft.com/blog/2015/06/android-support-library/
Thanks also to Gabriele Mariotti for pointing me in the right direction. I will address the White Labeling conversion to Gradle in another question. Please chime in if I have this all incorrect...I will be the first to admit this is all very confusing!
My question is : do I still need to have the upgraded versions of these libs here or is this done via a Gradle addition for running out Android Studio?
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.android.gms:play-services:+'
Using the latest version is always a good idea
You should avoid using the the wildcard + in your dependencies, because in this way you are not able to replicate the same build in different time (because it changes in the time).
Use the same version of support libraries. The gms libraries have a dependencies with the support-v4 and you should use the same version.
it is not a good idea to have all gms modules (com.google.android.gms:play-services). You can add only the required modules.
And if not by lib dependencies as listed, how can I have the Ant build pick these upgrades once I make them?
It is not so simple. In my opinion you should convert your ant script in gradle. It would be easier.

NDK files not syncing with Gradle Android

I am doing a project on Beaglebone Black and i have ported Android KitKat on it. Now i need an android app that could help me access those gpios on beaglebone for a project.
So i am using android studio 1.3.1 to create my application for my project and so to access the hardware pins via android i have to use NDK for it. Now when i am trying to sync gradle 2.2.1 with my NDK files it prints an error that i should set android.useDeprecatedNdk=true. Now when i do that it again shows the error that DeprecatedNdk() is not defined.
Although i have downloaded the latest version of NDK i.e. android-ndk-r10e from android developers website but the error still persists.
Following is the build.gradle file from the module.
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.packt.gpio"
minSdkVersion 19
targetSdkVersion 19
ndk {
moduleName "packtHAL"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.+'
}
Also the error that it is showing is:
Error:(14, 0) Error: NDK integration is deprecated in the current plugin.
Consider trying the new experimental plugin. For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration.
And if i add the property to the file then it shows the following error:
Error:(6, 0) Gradle DSL method not found: 'useDeprecatedNdk()'
Possible causes:The project 'gpio' may be using a version of Gradle that does not contain the method.
The build file may be missing a Gradle plugin.
If anyone has any idea as to what should be done regarding this. Please share your ideas.
Thank you
Please check the new documentation: http://tools.android.com/tech-docs/android-ndk-preview
Here are the latest project setup instructions: http://tools.android.com/tech-docs/new-build-system/gradle-experimental
This just popped up too: http://ph0b.com/new-android-studio-ndk-support/

Android Studio: Failed to find: 'com.android.support:support-v4:19.1.0'

I want to build an app in Android Studio with the support library but I get the following error when adding the dependency for the support library:
Error:Failed to find: com.android.support:support-v4:19.1.0
Here is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '20'
defaultConfig {
applicationId "sample.myapplication"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:19.1.0'
}
I have downloaded the support library via the sdk manager.
Ok, found the problem. The Android support repository was missing. After installing and restarting Android Studio it worked.
If you are using Android Studio, then as an addition to changing the build.gradle file manually, you can also lookup the dependency via the library dependencies under the Project Structure menu item.
Double clicking that dependency will generate this line in build.gradle:
dependencies {
compile 'com.android.support:support-v13:+'
}
And also, if you are wondering what this library is about, it's described at the developer pages at developer.android.com; Support Library.
My Android Studio version is 1.1. I select tools->Android->SDK Manager, check the Android Support Library then click Install packages, solved this issue.
In my case the solution was as simple as running Build:Make Project. No amount of gradle syncing or clearing caches would do it. Of course, that required getting my project into a state where it would build successfully.
In my case I needed to add Google Maven repository.
It shows as part of the error in Android Studio and only needed to click on it to add itself.
Then Gradle built the project on its own.
Following the instruction here helped me. For whatever reason when I had to reinstall the latest version of android studio the initial download of the extras section android support library failed. I simply retried it. Followed the steps mentioned and verified it was added to the build.gradle file and did a rebuild project and good to go.
http://developer.android.com/tools/support-library/setup.html

Add support library to Android Studio project

I just installed the new Android Studio and I'm looking for a way to import the support library for Android.
Where is the option for that? In Eclipse that are just two clicks. I googled for it but found nothing. Surely it is too new.
=============UPDATE=============
Since Android Studio introduce a new build system: Gradle. Android developers can now use a simple, declarative DSL to have access to a single, authoritative build that powers both the Android Studio IDE and builds from the command-line.
Edit your build.gradle like this:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 18
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.+'
}
NOTES: Use + in compile 'com.android.support:support-v4:21.+' so that gradle can always use the newest version.
==========DEPRECATED==========
Because Android Studio is based on IntelliJ IDEA, so the procedure is just same like on IntelliJ IDEA 12 CE
1.Open Project Structure (Press F4 on PC and Command+; on MAC) on your project).
2.Select Modules on the left pane.
3.Choose your project and you will see Dependencies TAB above the third Column.
4.Click on the plus sign in the bottom. Then a tree-based directory chooser dialog will pop up, navigate to your folder containing android-support-v4.jar, press OK.
5.Press OK.
I no longer work on Android project for a while.
Although the below provides some clue to how an android studio project can be configured, but I can't guarantee it works flawlessly.
In principle, IntelliJ respects the build file and will try to use it to configure the IDE project. It's not true in the other way round, IDE changes normally will not affect the build file.
Since most Android projects are built by Gradle,
it's always a good idea to understand this tool.
I'd suggest referring to #skyfishjy's answer, as it seems to be more updated than this one.
The below is not updated
Although android studio is based on IntelliJ IDEA, at the same time it relies on gradle to build your apk. As of 0.2.3, these two doesn't play nicely in term of configuring from GUI.
As a result, in addition to use the GUI to setup dependencies, it will also require you to edit the build.gradle file manually.
Assuming you have a Test Project > Test structure.
The build.gradle file you're looking for is located at TestProject/Test/build.gradle
Look for the dependencies section, and make sure you have
compile 'com.android.support:support-v4:13.0.+'
Below is an example.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
You can also add 3rd party libraries from the maven repository
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
The above snippet will add gson 2.2.4 for you.
In my experiment, it seems that adding the gradle will also setup correct IntelliJ dependencies for you.
This is way more simpler with Maven dependency feature:
Open File -> Project Structure... menu.
Select Modules in the left pane, choose your project's main module in the middle pane and open Dependencies tab in the right pane.
Click the plus sign in the right panel and select "Maven dependency" from the list. A Maven dependency dialog will pop up.
Enter "support-v4" into the search field and click the icon with magnifying glass.
Select "com.google.android:support-v4:r7#jar" from the drop-down list.
Click "OK".
Clean and rebuild your project.
Hope this will help!
You can simply download the library which you want to include and copy it to libs folder of your project. Then select that file (in my case it was android-support-v4 library) right click on it and select "Add as Library"
In Android Studio 1.0, this worked for me :-
Open the build.gradle (Module : app) file and paste this (at the end) :-
dependencies {
compile "com.android.support:appcompat-v7:21.0.+"
}
Note that this dependencies is different from the dependencies inside buildscript in build.gradle (Project)
When you edit the gradle file, a message shows that you must sync the file. Press "Sync now"
Source : https://developer.android.com/tools/support-library/setup.html#add-library
Android no longer downloading the libraries from the SDK manager, it has to be accessed through Google's Maven repository.
You will have to do something similar to this in your build.gradle file:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
dependencies {
...
compile "com.android.support:support-core-utils:27.0.2"
}
Find more details about the setting up process here and about the different support library revisions here.
AndroidX[About]
implementation 'androidx.appcompat:appcompat:1.0.2'

Categories

Resources