I am trying to make Android App bundles for Google Play using Android Studio. Android Studio told that I need to upgrade Gradle for that. I migrated Gradle to 7.0.0 version (and updated Android Studio itself), but I am totally new in this, so now I have issues with Maven. I got the following error:
Build file
'/Users/administrator/noughts-and-crosses/node_modules/expo-application/android/build.gradle'
line: 2
A problem occurred evaluating project ':expo-application'.
Plugin with id 'maven' not found.
I found that maven is not used anymore, so I need to migrate to maven-publish. I changed maven to maven-publish, but now I have the following issue:
Build file
'/Users/administrator/noughts-and-crosses/node_modules/expo-application/android/build.gradle'
line: 28
A problem occurred evaluating project ':expo-application'.
Could not find method uploadArchives() for arguments [build_6lgwxdh9lx7r2mkhkk2he2s1g$_run_closure4#56af98de] on project
':expo-application' of type org.gradle.api.Project.
The build.gradle file with the issue looks like that:
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
group = 'host.exp.exponent'
version = '3.1.2'
// Simple helper that allows the root project to override versions declared by this library.
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
// Upload android library to maven with javadoc and android sources
configurations {
deployerJars
}
// Creating sources with comments
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
// Put the androidSources and javadoc to the artifacts
artifacts {
archives androidSourcesJar
}
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
repository(url: mavenLocal().url)
}
}
}
android {
compileSdkVersion safeExtGet("compileSdkVersion", 30)
defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 30)
versionCode 12
versionName '3.1.2'
}
lintOptions {
abortOnError false
}
}
if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
apply from: project(":unimodules-core").file("../unimodules-core.gradle")
} else {
throw new GradleException(
'\'unimodules-core.gradle\' was not found in the usual React Native dependency location. ' +
'This package can only be used in such projects. Are you sure you\'ve installed the dependencies properly?')
}
dependencies {
unimodule 'unimodules-core'
implementation 'com.android.installreferrer:installreferrer:1.0'
}
So, the question is: how to fix the new issue?
Update. I read the article from the comment, and now the file looks like this:
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
// Simple helper that allows the root project to override versions declared by this library.
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
// Upload android library to maven with javadoc and android sources
configurations {
deployerJars
}
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
groupId = 'host.exp.exponent'
artifactId = 'noughts-and-crosses'
version = '3.1.2'
artifact(sourcesJar)
}
}
}
}
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
repository(url: mavenLocal().url)
}
}
}
android {
compileSdkVersion safeExtGet("compileSdkVersion", 30)
defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 21)
targetSdkVersion safeExtGet("targetSdkVersion", 30)
versionCode 12
versionName '3.1.2'
}
lintOptions {
abortOnError false
}
}
if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
apply from: project(":unimodules-core").file("../unimodules-core.gradle")
} else {
throw new GradleException(
'\'unimodules-core.gradle\' was not found in the usual React Native dependency location. ' +
'This package can only be used in such projects. Are you sure you\'ve installed the dependencies properly?')
}
dependencies {
unimodule 'unimodules-core'
implementation 'com.android.installreferrer:installreferrer:1.0'
}
But it didn't solve the problem.
Related
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
I have cloned a project from github and getting the following error while building up the project: "The "android" command is no longer included in the SDK. Any references to it (e.g. by third-party plugins) should be removed."
The gradle file is:
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'signing'
// Scheme for version codes: ####$$$ , using:
// ## - the first two digits for the API Level,
// ## - the second and third digits for the minimum and maximum screen size
// (1 - 4 indicating each of the four sizes) or to denote the texture formats
// $$$ - the last three digits for the app version.
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
versionCode 800410
versionName "4.1"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
}
}
allprojects {
// show deprecation warnings for all projects
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
options.compilerArgs << "-Xlint:unchecked"
}
}
dependencies {
compile 'com.jakewharton.timber:timber:2.7.1'
}
version = "4.1.0"
//version = '2.9.0-SNAPSHOT'
group = "be.shouldit"
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
if (isReleaseVersion) {
println 'Building RELEASE'
ext.sonatypeRepo = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
} else {
println 'Building SNAPSHOT'
ext.sonatypeRepo = "https://oss.sonatype.org/content/repositories/snapshots/"
}
ext.sonatypeUsername = hasProperty("sonatypeUsername") ? sonatypeUsername : ""
ext.sonatypePassword = hasProperty("sonatypePassword") ? sonatypePassword : ""
configurations {
archives {
extendsFrom configurations.default
}
}
repositories {
mavenCentral()
}
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task publishLocal(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
repository(url: "file://$buildDir/repo")
}
}
uploadArchives {
configuration = configurations.archives
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: project.ext.sonatypeRepo) {
authentication(userName: project.ext.sonatypeUsername,
password: project.ext.sonatypePassword)
}
pom.project {
name 'Android Proxy Library'
packaging 'aar'
description 'Proxy utility library for Android applications'
url 'https://github.com/shouldit/android-proxy'
scm {
url 'scm:git#github.com:shouldit/android-proxy.git'
connection 'scm:git#github.com:shouldit/android-proxy.git'
developerConnection 'scm:git#github.com:shouldit/android-proxy.git'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'lechuckcaptain'
name 'abc'
email 'abc#gmail.com'
}
}
}
}
}
Links that I have already tried:
https://stackoverflow.com/questions/42720255/errorthe-android-command-is-no-longer-included-in-the-sdk-any-references-to?noredirect=1&lq=1
https://github.com/stetro/project-tango-poc/issues/9
etc.
I know that this question has already been asked but the solutions are not working for me as in the above gradle file there is not "sdk or apt" plugin used so please help to solve this issue.
Finally I have solved this issue, there was one more package in the project having build.gradle file, from there i removed plugin of sdk manager and error gone.
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'
}
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)
}
I am trying to know how to get gradle to download the source of a given dependency. All that I've searched has not work. I've seen the property DownloadSources. But I do not know where to write it in my Android gradle file.
I've tried to write it in different locations, inside dependencies {}, android { }, defaultConfig {}. But no luck. In a regular gradle file like this, where have I to use downloadsources?:
Project file
sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
//..
}
}
allprojects {
repositories {
// ..
}
}
Module file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
// ...
}
buildTypes {
release {
//....
}
}
}
dependencies {
// ...
compile 'it.neokree:MaterialNavigationDrawer:latest.release'
}
Sorry if its a dummy question, but I can not find a solution.
You can set it for all dependencies. For idea use:
idea {
module {
downloadSources = true
}
}
For Eclipse:
eclipse {
classpath {
downloadSources=true
}
}