Search code examples
javaandroidgradleimporterrorandroid-library

Can't access class files from project which I imported as a library


I imported a project as a library in my base project but I am not able to access the class files present in my imported library , in my base project. Forgive me if the question is stupid , I am relatively new in android studio Steps I did -

  1. Changed apply plugin: 'com.android.application' to apply plugin: 'com.android.library'
  2. Added Implementation project(':project_name')
  3. Changed the compileSdkVersion, minSdkVersion and targetSdkVersion to the same values
  4. Did an Invalidate Cache / Restart Following are my gradle files

build.gradle(:app) (Main Project)

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.consensus.deg_project"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:25.12.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-auth:19.4.0'
    implementation 'com.google.firebase:firebase-firestore:22.0.0'
    implementation 'com.google.android.gms:play-services-auth:18.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'com.google.firebase:firebase-database:19.2.0'
    implementation('com.google.api-client:google-api-client-android:1.23.0') {
        exclude group: 'org.apache.httpcomponents'
        exclude group:'com.google.guava'
    }
    implementation('com.google.apis:google-api-services-sheets:v4-rev506-1.23.0') {
        exclude group: 'org.apache.httpcomponents'
        exclude group:'com.google.guava'
    }
    implementation 'com.shobhitpuri.custombuttons:google-signin:1.0.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.navigation:navigation-fragment:2.3.1'
    implementation 'androidx.navigation:navigation-ui:2.3.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'me.dm7.barcodescanner:zxing:1.9'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'pub.devrel:easypermissions:0.3.0'
    implementation project(':TF_Lite')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}

build.gradle(:TF_Lite) (Project imported as a library)

apply plugin: 'com.android.library'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "org.tensorflow.lite.examples.classification"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    aaptOptions {
        noCompress "tflite"
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
    lintOptions {
        abortOnError false
    }
    flavorDimensions "tfliteInference"
    productFlavors {
       // The TFLite inference is built using the TFLite Support library.
       support {
           dimension "tfliteInference"
       }
       // The TFLite inference is built using the TFLite Task library.
       taskApi {
           dimension "tfliteInference"
       }
   }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    supportImplementation project(":lib_support2")
    taskApiImplementation project(":lib_task_api2")
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'com.google.truth:truth:1.0.1'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.1.0'
}

Solution

  • So all i had to do was add this:-

    flavorDimensions "tfliteInference"
        productFlavors {
            // The TFLite inference is built using the TFLite Support library.
            support {
                dimension "tfliteInference"
            }
            // The TFLite inference is built using the TFLite Task library.
            taskApi {
                dimension "tfliteInference"
            }
        }
    

    in my main project's build gradle