Android + Gradle; Cannot access support-v4:23.x.x - android

Being used to ANT for configuring Android projects in Netbeans, I am new to Android Studio and Gradle.
(In both Netbeans and Android Studio) I am struggling a bit with Gradle dependencies to the last versions of the Android support-v4 library. Everything is fine as long as version is set below 23.0.0, i.e. 22 21 etc, but when using support-v4:23.x.x, things go awry.
To investigate this problem, I have made a minimalist project consisting of one FragmentActivity only. Specifying v4 23, it cannot find any core methods of Activity or FragmentActivity, like e.g. getWindow()
I have tried both mavenCentral() and mavenLocal().
Thanks for any help.
EDIT: The build.gradle content added below.
import org.gradle.api.artifacts.*
apply plugin: 'base' // To add "clean" task to the root project.
subprojects {
apply from: rootProject.file('common.gradle')
}
task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') {
title = 'All modules'
destinationDir = new File(project.buildDir, 'merged-javadoc')
// Note: The closures below are executed lazily.
source {
subprojects*.sourceSets*.main*.allSource
}
}
buildscript {
repositories {
jcenter()
}
//Make sure that gradle is updated to this version
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
repositories {
mavenLocal()
mavenCentral() //se viktig kommentar 030416
flatDir {dirs 'libs'}
}
apply plugin: 'com.android.application'
ext {
supportLibVersion = '23.2.1'
//versionName = '2.8.0'
}
android {
compileSdkVersion 23
buildToolsVersion = '23.0.3' //"21.1.2"
//publishNonDefault true
defaultConfig {
//minSdkVersion 15 //Spotify requires min14, Facebook min15
//targetSdkVersion 23
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
buildTypes {
debug {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, output.outputFile.name.
replace(".aar", "-${versionName}.aar"))
}
}
}
}
}
dependencies {
//support
compile ('com.android.support:support-v4:23.2.1')
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}

Related

What are the minimal Gradle settings needed to support converting Kotlin files in an Android Studio App into Javascript using kotlin2js?

Currently, I have two build.gradles. One for the app, and one for the project.
For the App build.gradle, I have:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 19
buildToolsVersion '28.0.2'
defaultConfig {
applicationId "someId"
minSdkVersion 11
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/someSDK.jar')
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
For the Project build.gradle, I have:
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin2js'
allprojects {
repositories {
mavenCentral()
jcenter()
}
}
sourceSets {
main.kotlin.srcDirs += "${projectDir}/src/main/java/pathToFilesConvertedFromJavaToKotlin"
}
compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
kotlinOptions.main = "call"
}
ext {
minSdkVersion = 15
targetSdkVersion = 23
compileSdkVersion = 23
buildToolsVersion = '23.0.3'
xmlunitVersion = '1.6'
junitVersion = '4.12'
mockitoVersion = '1.10.19'
hamcrestVersion = '1.3'
}
When I compile and run, the app works and no errors occur. However, I do not see my javascript file that should have been produced from those Kotlin files.
Any ideas as to why?
Please note, I have tried using: http://kotlinlang.org/docs/tutorials/javascript/getting-started-gradle/getting-started-with-gradle.html as a guide. The issue with this example is that it suggests using the taskAssemble below. However, this contains File, which is not recognized as a keyword in my build.gradle for some reason.
task assembleWeb(type: Sync) {
configurations.compile.each { File file ->
from(zipTree(file.absolutePath), {
includeEmptyDirs = false
include { fileTreeElement ->
def path = fileTreeElement.path
path.endsWith(".js") && (path.startsWith("META-INF/resources/") ||
!path.startsWith("META-INF/"))
}
})
}
from compileKotlin2Js.destinationDir
into "${projectDir}/web"
dependsOn classes
}
assemble.dependsOn assembleWeb
As of right now, I believe the issue is that you cannot compile Java Byte Code into Javascript via kotlin2js. Since I have Android references in my code, and those references are compiled into Java Byte Code, my Kotlin scripts cannot successfully be converted into Javascript. However, I have come across an interesting article that could be of use to anyone looking to build Kotlin based applications that can work across multiple platforms: https://kotlinlang.org/docs/reference/multiplatform.html

Android Studio 2.1.3 - DefaultSourceDirectorySet issue

Updated Android Studio from 2.1.2 -> 2.1.3 this morning and receiving the following gradle sync error:
Error:Unable to find method
'org.gradle.api.internal.file.DefaultSourceDirectorySet.(Ljava/lang/String;Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;)V'.
I'm pretty sure it's related to the following library project:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.0'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
minifyEnabled false
}
}
sourceSets {
main {
proto {
srcDir 'src/main/protos'
}
java {
srcDir 'src/main/java'
}
manifest {
srcFile 'src/main/AndroidManifest.xml'
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-2'
compile project(':wallpaperpicker-resources')
}
protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.0.0-alpha-3'
}
}
Looks like my previous gradle plugin version was 1.3.0 - am I missing some change that occurred related to the sourceSets block?
Try to update the protobuf version:
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
ced's answer led me to the solution. It appears that newer versions of gradle, the Android Studio gradle plugin, and the google protoc plugin wouldn't play nice. I had to upgrade the google protoc plugin as ced noted - but this was a large departure from 0.7.0. The javanano protoc compiler is no longer recommended (and I couldn't get it to work at all). This is the javalite solution that I ended up using.
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
minifyEnabled false
}
}
sourceSets {
main {
proto {
srcDir 'src/main/proto'
}
java {
srcDirs = ['src/main/java','$buildDir/generated-sources/release/javalite']
}
manifest {
srcFile 'src/main/AndroidManifest.xml'
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-2'
compile 'com.google.protobuf:protoc-gen-javalite:3.0.0'
compile 'com.google.protobuf:protobuf-lite:3.0.0'
compile project(':wallpaperpicker-resources')
}
protobuf {
generatedFilesBaseDir = "$projectDir/build/generated-sources"
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
// The codegen for lite comes as a separate artifact
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {
//remove some of the javalite extra packaging
outputSubDir = ''
}
}
}
}
}
apply plugin: 'idea'
idea {
module {
sourceDirs += file("$buildDir/generated-sources/release/javalite");
}
}

preBuild dependency in new experimental Gradle for NDK on Android Studio

Recently i decided to take the new NDK plugin in Android Studio for a ride
The changes needed are explained here
My build.gradle was ported successfully. Today i decided that i need a copy task in order to copy files into my 'asset' folder.
Searching online says that i must use a 'preBuild.dependsOn taskName' line, which i am sure works Ok for normal Gradle, but fails in the new experimental one (With the introduction of the 'model' behaviour)
Now my build.gradle fails.
Error:(25, 0) Could not find property 'preBuild' on root project 'Android'.
I am sure that the task is defined correctly, since the error comes from the preBuild... line
Here is my build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.0'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.model.application'
task copyWebViewAssets(type: Copy){
from '../Common/WebView'
into 'src/main/assets'
include('**/*')
}
preBuild.dependsOn copyWebViewAssets
model {
compileOptions.with {
sourceCompatibility=JavaVersion.VERSION_1_7
targetCompatibility=JavaVersion.VERSION_1_7
}
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "com.company.product"
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
}
android.ndk {
moduleName = "native"
}
android.buildTypes {
release {
minifyEnabled = false
}
debug {
ndk.with {
debuggable = true
}
}
}
android.productFlavors {
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
}
I would like to address again that this is related to the new experimental Gradle for NDK. I am currently on Android Studio 1.4, using Gradle 2.5.
Thank you for your support
Use compileTask instead of prebuild
it works for me.
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(changeNamespace)
}

Parse.com - can't find build.gradle file

ParseStarterProject is really, really frustrating. I tried to add Google Play services to compile in build.gradle and it don't wanted to sync. Then I removed it to make it work again, but it showed that there is settings.gradle file missing. When I tried to create it by myself - it fails to save it... Now I have Failed to resolve: com.parse.bolts:bolts-android:1.2.0 and I don't know what to do with it. I want to make a new project from scratch and copy my code, but seems like it's more complicated than just copy & paste.
ParseStarterProject.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.parse'
buildscript {
repositories {
mavenCentral()
jcenter()
maven { url 'https://maven.parse.com/repo' }
}
dependencies {
classpath 'com.parse.tools:gradle:1.+'
}
}
dependencies {
compile 'com.parse.bolts:bolts-android:1.2.0'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile fileTree(dir: 'libs', include: 'ParseCrashReporting-*.jar')
}
android {
compileSdkVersion 22
buildToolsVersion "20"
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
/* Uncomment if you enable ProGuard and you want to automatically upload symbols on build.
parse {
applicationId YOUR_APPLICATION_ID
masterKey YOUR_MASTER_KEY
// Make symbol upload automatic. Otherwise, use e.g. ../gradlew parseUploadSymbolsDebug;
uploadSymbols true
}
*/
build.gradle
// 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:1.1.3'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
ext {
compileSdkVersion = 22
buildToolsVersion = "22"
minSdkVersion = 9
targetSdkVersion = 22
}

ActionBarSherlock (library) on Android Studio

I had the problem like wired00 on Problems importing project into Android Studio regarding ActionBarSherlock
I do exactly the solution (Edit2) but when I run I get
Gradle: package com.actionbarsherlock.app does not exist
Strange thing is that on code I don't get any error, just on compiling.
Update 1:
build.gradle:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
MainActivity:
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockActivity;
public class MainActivity extends SherlockActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Module Settings:
Structure:
Error:
I think you need to add the following dependency in you gradle file:
compile project(':StoKit:actionbarsherlock')
(within the dependency section)
EDIT 25/05/2013
Ok, so this is my project structure which is currently compiling fine in android studio and via gradle command line:
EDIT 31/05/2013
Ok, so my build.gradle file within DecisionBuddy-DecisionBuddy module is:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
repositories{
mavenCentral()
}
dependencies {
compile project(':libraries:actionbarsherlock')
compile files('libs/GoogleAdMobAdsSdk-6.3.1.jar')
compile files('libs/libGoogleAnalyticsV2.jar')
compile files('libs/mobileservices-0.2.0.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
And the one in the actionbarsherlock module is:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('../../DecisionBuddy/libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Does this help?
Also make sure you updated to the latest version of the tools - I was having some issues until I did that.
I had the same problem and solve it by adding
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
to the dependencies of the build.gradle of the slidingMunu library project.
here is my build.gradle
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
android {
compileSdkVersion 16
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}

Categories

Resources