I have written a build.gradle file for my Android App. The App uses AndroidAnnotations.
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.3.2'
buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'org.androidannotations:androidannotations:3.3.2'
}
}
configurations {
apt
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName "de.xxx"
}
}
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "de.xxx"
minSdkVersion 11
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:23.1.1'
compile files('libs/acra-4.3.0.jar')
}
The script does the APT profecessing and generates the Annotation_ classes. But afterwards the script fails with compilation of import-Statements and usages of classes like
import com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.EFragment;
import com.googlecode.androidannotations.annotations.ViewById;
Whats wrong with the script? I know there is room for improvement.
Use this build.gradle :
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
def AAVersion = '3.3.2'
buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apt {
arguments {
androidManifestFile variant.outputs[0]?.processResources?.manifestFile
resourcePackageName "de.xxx"
}
}
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "de.xxx"
minSdkVersion 11
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:23.1.1'
compile files('libs/acra-4.3.0.jar')
}
The example script can be found in the guide, or in the sample project.
Change the import statements like:
import org.androidannotations.annotations.AfterViews;
Related
I have created the account and key needed from Mapbox. I have listed the repositories in different order with no luck. Whn building, the following error appears:
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom
- https://repo.maven.apache.org/maven2/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom
Required by:
project :app > com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.1
Here's my build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.20"
repositories {
google()
mavenCentral()
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = 'mapbox'
// Use the secret token you stored in gradle.properties
password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
}
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I've added the following to my module level build.gradle
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.1'
I have only added jcenter() and it works. However, jcenter() is deprecated.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
It seem like they remove mapbox-android-accounts repository.
Check this: https://mvnrepository.com/artifact/com.mapbox.mapboxsdk/mapbox-android-accounts/0.8.0
Github page is empty.
Works for me after jcenter() added.
I added jcenter() to buildscript -> repositories and allprojects -> repositories:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"
}
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
username "mapbox"
password "YOUR_TOKEN"
}
}
google()
maven { url 'https://www.jitpack.io' }
}
}
I am trying to build a multi-project build in Gradle using Kotlin DSL.
Root build.gradle.kts:
allprojects {
repositories {
jcenter()
google()
}
}
subprojects{
version = "1.0"
}
plugins {
java
application
}
repositories {
jcenter()
}
dependencies {
implementation("com.google.guava:guava:27.0.1-jre")
testImplementation("junit:junit:4.12")
}
application {
mainClassName = "gradle.youtube.series.App"
}
gitutils subproject's build.gradle.kts
plugins {
`java-library`
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.sl4j:sl4j-api:1.7.2")
implementation("org.eclipse.jgit:org.eclipse.jgit:5.3.0.201903130848-r")
testImplementation("org.junit.jupiter:junit-jupiter:5.4.1")
testRuntimeOnly("org.sl4j:sl4j-simple:1.7.2")
}
tasks.test {
useJUnitPlatform()
}
I am trying to download gradeutil's dependencies using the following command:
./gradlew gitutils:dependencies --configuration complileClasspath
I am getting the following error:
Configuration with name 'complileClasspath' not found.
Is compileClassPath required for multi-level gradle project? What is its use?
From https://kotlinlang.org/docs/tutorials/javascript/getting-started-gradle/getting-started-with-gradle.html I got the following build.gradle (groovy) script :
group 'org.example'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin2js'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}
I tried this translation :
group 'org.example'
version '1.0-SNAPSHOT'
buildscript {
extra["kotlinVersion"] = "1.3.61"
repositories {
jcenter()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${extra["kotlinVersion"]}")
}
}
plugins {
kotlin2js // <= this is incorrect
application
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-js:${extra["kotlinVersion"]}")
}
application {
mainClassName = "io.ipfs.kotlin.MainIpfsKt"
}
gradle emits the following error message
kotlin2js
^ Unresolved reference: kotlin2js
What is the correct translation for apply plugin: 'kotlin2js' ?
I have a project with the following modules:
App
Device
App depends on device. Device contains a NetworkComponent class that app references. More specifically:
package com.some.package.ui.login;
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.some.package.R
import com.some.package.device.network.NetworkComponent
import com.some.package.ui.terms.TermsActivity
class LoginActivity : AppCompatActivity(),
LoginViewModel.Navigator {
val loginViewModel by lazy { LoginViewModel(this, NetworkComponent()) }
Everything resolves fine in Android Studio. Yet when I attempt to build the project, I encounter a build error:
e: /Users/android/some-app-android/app/src/main/kotlin/com/some/package/ui/login/LoginActivity.kt: (7, 27): Unresolved reference: network
e: /Users/android/some-app-android/app/src/main/kotlin/com/some/package/ui/login/LoginActivity.kt: (13, 55): Unresolved reference: NetworkComponent
[KOTLIN] deleting /Users/android/some-app-android/app/build/tmp/kotlin-classes/debug on error
[KOTLIN] deleting /Users/android/some-app-android/app/build/tmp/kotlin-classes/debug on error
:app:compileDebugKotlin FAILED
This is what NetworkComponent looks like:
package com.some.package.device.network
import com.some.package.domain.datasources.CodeValidator
import retrofit2.Retrofit
class NetworkComponent : CodeValidator {
val codeValidator: CodeValidatorApi
init {
val retrofit = Retrofit.Builder()
.baseUrl("www.test.com")
.build()
codeValidator = retrofit.create(CodeValidatorApi::class.java)
}
override fun validate(code: String) = codeValidator.validate(code)
}
Here are the build files:
Top:
buildscript {
ext.kotlin_version = '1.1.51'
ext.android_tools = '3.0.0'
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:$android_tools"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
App:
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
//apply plugin: 'io.fabric'
// Manifest version information
def versionMajor = 0
def versionMinor = 0
def versionPatch = 1
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.some.package"
minSdkVersion 21
targetSdkVersion 27
versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
// applicationIdSuffix '.debug'
resValue "string", "application_name", "TEST APP Debug"
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "application_name", "TEST APP"
}
}
dataBinding {
enabled = true
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
debug.java.srcDirs += 'src/debug/kotlin'
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/services/javax.annotation.processing.Processor' // butterknife
}
}
repositories {
maven { url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo' }
}
dependencies {
implementation project(':device')
implementation project(':data')
implementation project(':domain')
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:support-v4:27.0.0'
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:design:27.0.0'
implementation 'com.android.support:support-annotations:27.0.0'
kapt "com.android.databinding:compiler:$android_tools"
// Logging
implementation 'com.jakewharton.timber:timber:4.5.1'
// Unit tests
testImplementation 'junit:junit:4.12'
// testImplementation 'org.robolectric:robolectric:3.0'
testImplementation 'org.mockito:mockito-core:2.11.0'
// testImplementation 'joda-time:joda-time:2.9.4'
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.1'
// releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
// testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
implementation 'io.reactivex.rxjava2:rxkotlin:2.1.0'
debugImplementation 'com.facebook.stetho:stetho:1.4.1'
debugImplementation 'com.uphyca:stetho_realm:2.0.0'
// implementation('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
// transitive = true;
// }
}
Device:
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':domain')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'io.reactivex.rxjava2:rxkotlin:2.1.0'
implementation "com.squareup.retrofit2:retrofit:2.3.0"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
testImplementation 'junit:junit:4.12'
}
I'm not quite sure how this can happen. I tried downgrading the gradle plugin to 2.3.3, but no luck.
Any ideas?
Turns out I was missing this key line in my device module build file:
apply plugin: 'kotlin-android'
Thanks to this answer for the clue https://stackoverflow.com/a/31671696/918585
Related to
How to Get $project.version in Custom Gradle Plugin?
Executive summary: getVersion() inside of custom gradle plugin returns "unspecified"
I have created a custom gradle plugin that applies some business logic to our Android Studio / Gradle builds. This plugin is run every time we do a CI build.
I want the plugin to be able to print out its version, which is an entirely different version number from that of the Android application being built, during builds. (useful debugging information during CI builds)
The build.gradle for the plugin (that gets deployed to a maven repo as a jar):
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'groovy'
apply plugin: 'maven'
group = 'com.example.foo.gradle'
version = "0.0.12"
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
dependencies {
repositories {
mavenCentral()
}
compile gradleApi()
compile localGroovy()
}
configurations {
includeInJar
}
dependencies {
//testCompile 'junit:junit:4.11'
}
jar {
}
uploadArchives {
repositories.mavenDeployer {
def deployPath = file(getProperty('aar.deployPath'))
repository(url: "file://${deployPath.absolutePath}")
pom.project {
groupId project.group
artifactId 'foo-gradle-jenkins'
version project.version
}
}
}
... and the plugin is applied to an Android app like this (sensitive parts omitted):
buildscript {
repositories {
mavenCentral()
maven { url "../../../plugin_builds" }
}
dependencies {
classpath 'com.example.foo.gradle:foo-gradle-jenkins:0.0.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'foo'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.android.examplegradleapplication3"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
In the plugin I attempt to print its version like this:
#Override
void apply(Project project) {
project.configure(project) {
if (it.hasProperty("android")) {
if (isJenkinsBuild()) {
log("Plugin version: " + getVersion())
// ...
}
// ...
}
}
}
.. but whenever I perform gradle build of the Android app it thinks getVersion() is unspecified.
What should I be doing instead to track the plugin version at the time of another gradle build using it as a plugin?
AppExtension android = (AppExtension) project.extensions.findByName("android")
String versionName = android.defaultConfig.versionName
String versionCode = android.defaultConfig.versionCode
project.configure(project) { println getVersion() } is the same as println project.version. If this prints unspecified, the build script didn't set (project.)version.
As of Gradle 2.2, there isn't a built-in way for a plugin to declare or query its own version, but you could implement this yourself (for your own plugins).