首页 > 解决方案 > 无法从我作为库导入的项目中访问类文件

问题描述

我将一个项目作为库导入到我的基础项目中,但我无法在我的基础项目中访问我导入的库中存在的类文件。如果这个问题很愚蠢,请原谅我,我在 android studio 中相对较新我做的步骤 -

  1. 将应用插件:'com.android.application' 更改为应用插件:'com.android.library'
  2. 添加了实施项目(':project_name')
  3. 将 compileSdkVersion、minSdkVersion 和 targetSdkVersion 更改为相同的值
  4. 缓存无效/重新启动以下是我的 gradle 文件吗

build.gradle(:app) (主项目)

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) (作为库导入的项目)

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'
}

标签: javaandroidgradleimporterrorandroid-library

解决方案


所以我所要做的就是添加这个: -

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"
        }
    }

在我的主要项目的构建 gradle


推荐阅读