无法从我作为库导入的项目中访问类文件

Posted

技术标签:

【中文标题】无法从我作为库导入的项目中访问类文件【英文标题】:Can't access class files from project which I imported as a library 【发布时间】:2021-07-25 04:46:27 【问题描述】:

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

    将应用插件:“com.android.application”更改为应用插件:“com.android.library” 添加了实施项目(':project_name') 将 compileSdkVersion、minSdkVersion 和 targetSdkVersion 更改为相同的值 是否使缓存无效/重新启动 以下是我的 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'

【问题讨论】:

【参考方案1】:

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

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 中

【讨论】:

以上是关于无法从我作为库导入的项目中访问类文件的主要内容,如果未能解决你的问题,请参考以下文章

Android 无法导入库项目

尝试访问导入库中的方法时,Android Studio 显示“无法解析符号”

如何从我的项目访问我的MongoDB实例到我的xunit测试项目类?

无法将 Java 项目中的类文件导入同一项目中的另一个类文件

无法从我的项目根目录访问静态 build.html

将 jar 文件导入 Android Studio 但仍然无法解析我的课程?