I want to use the common module both on mobile and backend. In backend module everything works fine, but I can't use common module on mobile. When I was build mobile project I got an error: Project with path ':common' could not be found in project ':app'
Project tree:
kibar
.git
gradle
idea
backend
src
build.gradle
common
src
build.gradle
mobile
.gradle
.idea
app
src
build.gradle
proguard-rules.pro
build.gradle
settings.gradle
settings.gradle
kibar:settings.gradle
rootProject.name = 'kibar'
include 'backend', 'mobile', 'common'
common:build.gradle
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.2.71'
}
repositories {
mavenCentral()
}
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.2.71"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
backend:build.gradle
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
jcenter()
mavenCentral()
maven { url "http://dl.bintray.com/kotlin/kotlin-eap" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
apply plugin: 'application'
sourceCompatibility = 1.8
mainClassName = "App"
repositories {
jcenter()
mavenCentral()
maven { url "https://dl.bintray.com/kotlin/exposed" }
maven { url "http://dl.bintray.com/kotlin/kotlin-eap" }
}
dependencies {
compile project(":common")
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
kotlin {
experimental {
coroutines "enable"
}
}
idea {
module {
sourceDirs += files('build/generated/source/kapt/main', 'build/generated/source/kaptKotlin/main')
generatedSourceDirs += files('build/generated/source/kapt/main', 'build/generated/source/kaptKotlin/main')
}
}
sourceSets {
main.resources.srcDir('conf')
main.java.srcDirs += 'src/main/java'
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}
mobile:build.gradle
buildscript {
ext{
kotlin_version = "1.2.71"
lifecycle_version = "2.0.0"
}
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://maven.google.com" }
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha13'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://maven.google.com" }
maven { url "https://jitpack.io" }
}
}
mobile:settings.gradle
include ':app'
mobile.app:build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
buildToolsVersion = '28.0.3'
compileSdkVersion 28
defaultConfig {
versionCode 1
versionName "1.0"
applicationId "com.example"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
androidExtensions {
experimental = true
}
kapt {
generateStubs = true
}
kotlin {
experimental {
coroutines "enable"
}
}
dependencies {
compile project(':common')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.30.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.30.2'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.core:core-ktx:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
}
You should have only one settings.gradle file in your whole project, at root directory level. Remove the mobile/settings.gradle.
Gradle multi-project build is expecting a single settings.gradlefile located in project root directory , and this settings.gradlemust declare all sub-projects. In your case, you need to add mobile:app sub-project in your kibar:settings.gradle file:
rootProject.name = 'kibar'
include 'backend', 'mobile:app', 'common'
For reference: https://docs.gradle.org/current/userguide/build_lifecycle.html#sec:settings_file
Related
Getting Failed to resolve: com.github.barteksc:android-pdf-viewer:3.2.0-beta.1 when trying to add the package as an dependency.
Also tried to add jCentre as repository but that didn't work.
Suggestion of any other packages would be fine too.
project level gradle -
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module level gradle -
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.myapplication"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.leanback:leanback:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation 'com.github.bumptech.glide:glide:4.13.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
}
settings.gradle -
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "####"
include ':app'
Thanks in advance
edit your setting.gradle to the following:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
jcenter()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter()
}
}
rootProject.name = "####"
include ':app'
Include PDFView in your layout:
<com.github.barteksc.pdfviewer.PDFView
android:id="#+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
I have a problem in the Gradle files. As I have updated the Android Studio I had to update the dependencies as well, but I'm getting unresolved dependencies.
Project gradle:
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'io.fabric.tools:gradle:1.29.0'
classpath 'com.novoda:bintray-release:0.4.1'
classpath 'com.google.gms:google-services:4.1.0'
}
}
allprojects {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
}
app gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.packagename"
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
lintOptions {
disable "ResourceType"
}
}
ext {
googlePlayServicesVersion = "4.2.0"
}
dependencies {
implementation files('libs/icu4j-4_4_2_2.jar')
implementation files('libs/jsoup-1.6.3.jar')
implementation files('libs/ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar')
implementation files('libs/zip4j_1.2.6.jar')
implementation('com.crashlytics.sdk.android:crashlytics:2.9.9#aar') {
transitive = true;
}
implementation 'com.facebook.android:facebook-android-sdk:4.38.1'
// Google
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation'com.google.firebase:firebase-auth:16.1.0'
// Firebase
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.android.gms:play-services-ads:17.2.1'
implementation project(':pdflibrary')
implementation 'com.android.support:support-compat:27.0.2'
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support:customtabs:27.0.2'
implementation files('libs/junit-4.3.jar')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.android.gms:play-services-flags:16.0.1'
implementation 'com.google.android.gms:play-services-basement:16.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
pdfLibrary gradle:
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName '1'
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
publish {
userOrg = 'thefinestartist'
groupId = 'com.thefinestartist'
artifactId = 'finestwebview'
publishVersion = '1'
desc = 'Beautiful and customizable Android Activity that shows web pages within an app.'
website = 'https://github.com/TheFinestArtist/FinestWebView-Android'
}
This is the errors I'm getting knowing that min-sdk is set to 24 and I only in the gradle and I have removed it from both manifests (app & pdfLibrary):
I have tried suggestion from other SO questions, but nothing worked.
edit minSdkVersion to 21 instead of 24 in pdfLibrary gradle
an sync project
In the allprojects block you have to add the google() maven repo.
allprojects {
repositories {
google()
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
}
I'm developing an android application. I've an 'dependencies.gradle' file in the root project:
ext {
// Android
kotlinVersion = '1.2.51'
gradleVersion = '3.1.3'
}
The problem is that I can use this properties in the App 'build.gradle' file but can't use inside Root 'build.gradle' file and it gives me this error:
Could not get unknown property 'kotlinVersion' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
This is my 'Root Build Gradle':
apply from: 'dependencies.gradle'
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is my 'App Build Gradle' :
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.shimibox.client"
minSdkVersion 18
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
I've found the problem. The ext must be inside the buildscript block. So I moved the apply from: 'dependencies.gradle' inside of that block.
Now Root build.gradle file is:
buildscript {
apply from: 'dependencies.gradle'
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
Android Studio 2.3.3
My project bulid.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.3'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
classpath "io.realm:realm-gradle-plugin:3.5.0"
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 {
jcenter()
maven { url 'https://dl.bintray.com/jetbrains/anko' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
repositories {
mavenCentral()
}
My app build.gradle.
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
dexOptions {
jumboMode = true
}
defaultConfig {
applicationId "my.project.com"
minSdkVersion 15
targetSdkVersion 23
versionCode 53
versionName "1.1.13"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["resourcePackageName": android.defaultConfig.applicationId]
}
}
}
// exclude buildTypes = "debug" from build Variants
variantFilter { variant ->
if (variant.buildType.name.equals('debug')) {
variant.setIgnore(true);
}
}
buildTypes {
def APP_NAME_STAGE = "My project Stage"
def APP_ID_SUFFIX_STAGE = ".stage"
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
stage {
initWith(debug)
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
lintOptions {
abortOnError false
}
}
def AAVersion = '4.3.0'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile('com.digits.sdk.android:digits:1.11.0#aar') {
transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics:2.6.0#aar') {
transitive = true;
}
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.baoyz.swipemenulistview:library:1.3.0'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile 'com.google.code.gson:gson:2.7'
compile 'com.miguelcatalan:materialsearchview:1.4.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.3'
compile 'com.squareup.okhttp:okhttp:2.7.3'
compile 'com.theartofdev.edmodo:android-image-cropper:2.2.5'
compile 'commons-codec:commons-codec:1.9'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'org.apache.httpcomponents:httpcore:4.4.4'
compile 'org.apache.httpcomponents:httpmime:4.3.6'
compile 'us.feras.mdv:markdownview:1.1.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.jetbrains.anko:anko-sdk15:0.9.1'
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
testCompile 'junit:junit:4.12'
}
And project bulid and run success.
So now I want to add Realm. I add in build.gradle
apply plugin: 'realm-android'
And as result I get error.
Error:Annotation processor '__gen.AnnotationProcessorWrapper_stage_io_realm_processor_RealmProcessor' not found
Error:Execution failed for task ':app:compileStageJavaWithJavac'.
Compilation failed; see the compiler error output for details.
:app:compileDevJavaWithJavac
Destination for generated sources was modified by kapt. Previous value = myProject\app\build\generated\source\apt\dev
error: Annotation processor '__gen.AnnotationProcessorWrapper_dev_io_realm_processor_RealmProcessor' not found
I found solution. Two approach:
By apt plugin
in app's budile.gradle:
apply plugin: 'com.neenbedankt.android-apt'
apt {
arguments {
resourcePackageName android.defaultConfig.applicationId
androidManifestFile variant.outputs[0]?.processResources?.manifestFile
}
}
dependencies {
apt 'io.realm:realm-android-library:3.5.0'
apt "org.androidannotations:androidannotations:$AAVersion"
}
OR
By kapt plugin
apply plugin: 'kotlin-kapt'
kapt {
arguments {
arg( "resourcePackageName", android.defaultConfig.applicationId)
arg( "androidManifestFile",
variant.outputs[0]?.processResourcesTask?.manifestFile)
}
}
dependencies {
kapt 'io.realm:realm-android-library:3.5.0'
kapt "org.androidannotations:androidannotations:$AAVersion"
}
If you use Kotlin, then you'll need to use KAPT.
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
should be
kapt "org.androidannotations:androidannotations:$AAVersion"
and
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
should be
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
and
// javaCompileOptions {
// annotationProcessorOptions {
// arguments = ["resourcePackageName": android.defaultConfig.applicationId]
// }
// }
kapt {
arguments {
arg('resourcePackageName', android.defaultConfig.applicationId)
}
}
EDIT: based on https://stackoverflow.com/a/34708575/2413303
kapt {
arguments {
arg('androidManifestFile', variant.outputs[0]?.processResources?.manifestFile)
arg('resourcePackageName', android.defaultConfig.applicationId)
}
}
If that still doesn't work, then the question becomes AndroidAnnotations related.
I am trying to add a PinnedSectionListView from android arsenal.
the way to add say:
Add the specific repository to your build file:
repositories {
maven {
url "https://jitpack.io"
}
}
Add the dependency in your build file (do not forget to specify the correct qualifier, usually 'aar'):
dependencies {
compile 'com.github.beworker:pinned-section-listview:v1.0'
}
so i did that (build.gradle (Project)):
buildscript {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (Module): apply plugin: 'com.android.application'
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.jonathandg.listviewsections"
minSdkVersion 16
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.beworker:pinned-section-listview:v1.0#aar'
//compile 'com.beworker:pinned-section-listview:v1.0'
}
then the android studio message is
Error:(25, 13) Failed to resolve: com.beworker:pinned-section-listview:v1.0
The repositoty is in: https://android-arsenal.com/details/1/264
Try below Gragle dependency line
compile 'com.github.beworker:pinned-section-listview:1.1'