Setting gradle to Android O (API 26) - android

Android studio has automatically update the following components to API 26:
ROM - SDK to API 26
Android SDK Build-Tools 26
Android Emulator 26.0.3
Android SDK Platforms-Tools 26.0.0
Android SDK Tools 26.0.2
My gradle 2.3.3:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
applicationId "com.mycompany.myapplication"
minSdkVersion 15
targetSdkVersion 26
versionCode 4
versionName "0.0.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
/////////If I change it to 26.0.0 it gives errors.///////////
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
/////////////////////////////////////////////////////////////
testCompile 'junit:junit:4.12'
}
I have two questions (see commented line in Gradle):
How can I know the latest version of these libraries (I simply throw random numbers and try to up them until I found the latest version).
In the excluded group there is 'com.android.support', if I delete that do I need to specify those libraries? I see many people including 'com.android.support' libraries this way so there is a reason I guess to do so.
I searched in developer.android.com and the latest version is 24.2.0 (so really old I have been using 25.3.1).

If you really want to use the 26 version you could use the + character at the end of your dependencies.
compile 'com.android.support:appcompat-v7:26+'
This way, grade will take the latest version beginning with 26.?.? of your dependency. But you will get a warning from Android Studio, because between two different versions the behavior could eventually change and then produce random effect.
To know the latest version, just take a look here : https://developer.android.com/topic/libraries/support-library/revisions.html
And to finish, if you include 'com.android.support', you will include the whole library. And you certainly not need all the stuff included. If you only use recycler view just add :
compile 'com.android.support:recyclerview-v7:26.0.0-beta2'

Check https://developer.android.com/topic/libraries/support-library/revisions.html and set language to English at footer to check latest version of support library. Currently is 25.4.0 (stable) or 26.0.0 (beta 2)

Try this:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}

Thanks for reporting your issue.upcoming 6.0.0 release includes support for Java 8 features, therefore in order to run it (or any of the betas) you need to upgrade your project to include Java 8 support by adding this into you app's gradle file:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

Related

Android project does not compile when Jack is enable

While enabling jack I get following error
Error:Jar transformation: class files coming from an unsupported Java version Error:Execution failed for task
':app:transformClassesWithPreJackPackagedLibrariesForDebug'.
com.android.build.api.transform.TransformException: com.android.builder.core.JackToolchain$ToolchainException: Jack
compilation exception
My build gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "pl.develhopper.jaxygenaddclientlib"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
jackOptions { // DEPRECATED
enabled true
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.code.gson:gson:2.8.2'
compile 'javax.xml.bind:jaxb-api:2.3.0'
testCompile 'junit:junit:4.12'
}
Doe anyone has an error like this? Where does it come from?
Jack is deprecated. If you want to use Java 8 you should update Android Studio to 3.0, mostly because you don't need Jack to use Java 8 with Android Studio 3.0
Jack is flawed, I couldn't even get it to compile when I used it. In my experience, the entire thing is buggy. Android Studio 3.0 comes with Java 8 support without Jack, meaning you don't need to deal with it.
if you already are using Android Studio 3, you can just remove the jack code in general. It isn't needed. If you are on a lower version, upgrade and then remove the jack code.
And if you read this:
Android Studio provides built-in support for using certain Java 8 language features and third-party libraries that use them. As shown in figure 1, the default toolchain implements the new language features by performing bytecode transformations, called desugar, on the output of the javac compiler. Jack is no longer supported, and you should first disable Jack to use the Java 8 support built into the default toolchain.
you'll see that AS 3 (the version referenced at the start of the site, not included in this answer for brevity) has support for Java 8 without jack. And since jack is deprecated and (in my experience) bugged, upgrading is your best option to get Java 8

After Adding Facebook Android SDK dependencies i'm getting this error

After adding Android Facebook SDK dependencies
compile 'com.facebook.android:facebook-android-sdk:4.21.0'
I'm getting error in
compile 'com.android.support:appcompat-v7:25.3.1'
But Project is running fine.
All com.android.support libraries must use the exact same version
specification (mixing versions can lead to runtime crashes). Found
versions 25.3.1, 25.0.0. Examples include
com.android.support:animated-vector-drawable:25.3.1 and
com.android.support:cardview-v7:25.0.0 less... (Ctrl+F1)
There are some combinations of libraries, or tools and libraries, that
are incompatible, or can lead to bugs. One such incompatibility is
compiling with a version of the Android support libraries that is not
the latest version (or in particular, a version lower than your
targetSdkVersion.)
Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
repositories {
mavenCentral()
}
defaultConfig {
applicationId "sujeet.raj.com"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.facebook.android:facebook-android-sdk:4.21.0'
}
This problem occurs due to different version of dependency files get downloaded.
Explicitly put this as well in gradle file and sync again.
compile 'com.android.support:animated-vector-drawable:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
Under this directory you can find these libraries getting downloaded
Project Files/Your project/.idea/libraries
Don't ask me why but this solved it for me:
android {
/.../
configurations.all {
resolutionStrategy.force 'com.android.support:cardview-v7:27.1.0'
resolutionStrategy.force 'com.android.support:animated-verctor-drawable:27.1.0'
resolutionStrategy.force 'com.android.support:customtabs:27.1.0'
resolutionStrategy.force 'com.google.android.gms:play-services-base:12.0.1'
resolutionStrategy.force 'com.google.android.gms:play-services-auth:12.0.1'
}
}
You can solve this with one of the following solutions: original here
Run a Gradle dependency report to see what your full tree of dependencies is. From there, you will see which one of your libraries is asking for a different version of the Android Support libraries. For whatever it is asking for, you can ask for it directly with the 25.2.0 version, or use Gradle's other conflict resolution approaches to arrange to get the same version.
Run:
./gradlew -q dependencies <module-name>:dependencies --configuration compile
Example:
./gradlew -q dependencies app:dependencies --configuration compile
For me, the error disappeared after removing com.google.android.gms:play-services:10.2.0
And only include com.google.android.gms:play-services-location:10.2.0 and com.google.android.gms:play-services-maps:10.2.0 as they are the only two play services that I use.
I think the gms:play-services depend on some old components of the support library, so we need to add them explicitly ourselves.
Maybe I am too late for this, but well, trying to be helpful here... this is how I solve it.
open
project/your project/.idea/libraries
then head to facebook sdk and you can see this
library name="facebook-android-sdk-4.22.1"
use the number "4.22.1" into the one in build.gradle
this is how I do it, I am too a beginner myself.

Missing support library v7 23

In my Android studio I am only able to see the support libraries for the version 25.0.0 but my compile SDK version is 23 when I try to add com.android.support:recyclerview-v7:23.0.4 I get an error message that
Error:(27, 13) Failed to resolve: com.android.support:recyclerview-v7:23.0.4
but as per the SDK manager it shows that I have installed all the support libraries.
On top of that I am unable to locate the v7:23.0.4 libraries in the menu
File => Project Structure => Dependencies
Here are the screenshots
My Questions
Why am I unable to see the support libraries for the version v7:23.0.4 ?
If the support library is not installed how come it does not show in my SDK Manager ?
EDIT 1
Build.gradle(Module.app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "appnotic.quicknotes"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.2'
}
EDIT 2
1) it is not available from the repository, why? I don't know, but it is not the latest one for version 23, try com.android.support:recyclerview-v7:23.2.1 instead
2) you don't install the libraries with the SDK manager, that only install the source where gradle get the library from, the library itself gets downloaded when you build
I tried with 23.0.4 and could not get it, with 23.2.1 yes. If you can get version 25.0.0 it means that the repository is installed, maybe the gradle project is messed up somehow. Try to delete the project iml file and .idea folder and recreate it.

Android Studio Build.Gradle Sync Error

I am experiencing a problem building my application in Android Studio. I am using Android Studio 2.2 Preview 7. When I start up my Android Studio it gives an error:
The plugin is too old, please update to a more recent version, or set
ANDROID_DAILY_OVERRIDE environment variable to xxxxxxx.
It requests I fix plugin version and sync project. I have made all the required updates but the error remains. I have read similar questions on the issue but they don't seem to apply to my case.
Could you please assist in providing me with a working solution?
Here is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.mobileappdev.novarttech.sunshine"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
compile 'com.android.support:design:23.3.0'
testCompile 'junit:junit:4.12'
}
As per my observation it seems like you haven't updated Android SDK platform to version 25. First of all download and install android sdk platform and build tools from SDK Manager and use the following lines in your build.gradle(module app)
compileSdkVersion 25
buildToolsVersion "25.0.0"
Also update dependencies according to that. It should work then
As #claudio-redi says, you need to upgrade your build gradle tools.
Use build tools 2.2.2 to your root build.gradle:
classpath 'com.android.tools.build:gradle:2.2.2'
And change the gradle distribution to 2.14.1 in gradle/wrapper/gradle-wrapper.properties file with:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Or if you already have download the gradle distribution and place it in a directory, you can set it in your Android Studio from menu File->Setting->Gradle and set it as the following image:
Please be noted when you want to use API Level 25 you need to make sure that compileSdkVersion, buildToolsVersion, targetSdkVersion, and Support Library using the same API Level 25.

Android Gradle build error Need to connect with database

Do i need to add any jar file. or need to and any dependencies
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
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:23.0.1'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http. client:4.1.2'
compile "org.apache.httpcomponents:httpmime:4.2.3"
}
And it displays this error in console:
Warning:Dependency org.apache.httpcomponents:httpclient:4.5 is ignored for debug as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
Warning:Dependency org.apache.httpcomponents:httpclient:4.5 is ignored for release as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
On the contrary, you need to remove a dependency. The warning message is telling you that you're trying to import a dependency that's already included in Android. So you might not need the line
compile 'org.apache.httpcomponents:httpclient:4.5' #Try removing this line
Try removing it and see if the app works correctly. If it doesn't and you still need to import HttpClient, please refer to this page (it's posted just a few days go by apache.org, it doesn't get any more official than that).
The link above basically tells you that you should use:
Apache HttpClient 4.3 port for Android when targeting Android API 22 and older
dependencies {
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
}
or
Apache HttpClient packages for Android maintained by Marek Sebera when targeting Android API 23 and newer
dependencies {
compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'
}

Categories

Resources