Android Studio库项目引用未解析的符号

Android Studio库项目引用未解析的符号,第1张

概述我终于将我的eclipseandroid项目迁移到AndroidStudio.我创建了一个包含两个模块的项目.一个模块是一个图书馆项目.另一个是普通的活动项目,其中包括库模块.Project/app/(ActivityProject)br_lib/(LibraryProject)在应用程序的模块设置中,我向lib模块添加了

我终于将我的eclipse android项目迁移到Android Studio.我创建了一个包含两个模块的项目.一个模块是一个图书馆项目.另一个是普通的活动项目,其中包括库模块.

Project/   app/     (Activity Project)   br_lib/  (library Project)

在应用程序的模块设置中,我向lib模块添加了一个dependency.
lib模块项目正常构建,但每次我引用其中一个lib模块时,我的app模块构建都会失败:

import org.apache.http.clIEnt.httpClIEnt;import org.cddevlib.breathe.setup.Utils <--  // lib refrence;public class MainActivity extends Activity {    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        Utils.convertname(""); // <--- lib module static class;    }}

错误:

Error:(9, 34) error: cannot find symbol class UtilsError:(25, 9) error: cannot find symbol variable Utils

怎么了?我错过了什么?谢谢

这是应用程序模块gradle:

apply plugin: 'com.androID.application'androID {    compileSdkVersion 23    buildToolsversion "23.0.0"defaultConfig {    applicationID "pro.breathe.cddev.org.br_gold"    minSdkVersion 22    targetSdkVersion 22    versionCode 1    versionname "1.0"}buildTypes {    release {        MinifyEnabled false        proguardfiles getDefaultProguardfile('proguard-androID.txt'),     'proguard-rules.pro'        }    }}dependencIEs {    compile project(':br_lib')    compile filetree(dir: 'libs', include: ['*.jar']) }

这是lib模块gradle:

    apply plugin: 'com.androID.library'androID {compileSdkVersion 22buildToolsversion "23.0.0"defaultConfig {    minSdkVersion 9    targetSdkVersion 9}dependencIEs {    compile 'com.androID.support:support-v4:22.2.1'    compile 'com.androID.support:design:22.2.1'    compile 'com.androID.support:appcompat-v7:22.2.1'    compile 'com.androID.support:cardvIEw-v7:22.2.1'    compile 'com.androID.support:grIDlayout-v7:22.2.1'    compile 'com.androID.support:recyclervIEw-v7:22.2.1'    compile 'com.Google.androID.gms:play-services:7.8.0'}buildTypes {    release {        MinifyEnabled true        proguardfiles 'proguard.cfg'      }    }}dependencIEs {    compile filetree(dir: 'libs', include: ['*.jar'])}

这是项目的gradle:

buildscript {    repositorIEs {    jcenter()    }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()}}

设置gradle是:

include ':app', ':br_lib'

解决方法:

今天在一个有5个模块的项目中遇到了同样的问题(其中2个是com.androID.library模块).在对build.gradle文件进行了大量试验和错误更改之后,解决方案最终涉及在库模块的gradle文件中包含publishNonDefault true属性.

我发现这篇文章非常有帮助:
StackOverflow – Product Flavors and Library Publication

我的应用程序gradle文件最终看起来像(故意省略代码):

apply plugin: 'com.androID.application'androID {    compileSdkVersion 25    buildToolsversion '25.0.2'    packagingOptions {        exclude 'liCENSE.txt'        exclude 'NOTICE'        exclude 'meta-inf/liCENSE'    }    defaultConfig {    }    productFlavors {        funapp {            applicationID "com.funapp.package"        }        funappbeta {            applicationID "com.funapp.beta"        }    }    signingConfigs {        Googleplay {        }    }    buildTypes {        deBUG {            MinifyEnabled false            deBUGgable true            signingConfig signingConfigs.deBUG        }        release {            deBUGgable false            signingConfig signingConfigs.Googleplay        }    }}configurations {    funappDeBUGCompile    funappReleaseCompile    funappbetaDeBUGCompile    funappbetaReleaseCompile    // Establish deBUG compile dependencIEs for build variants    [funappDeBUGCompile, funappbetaDeBUGCompile].each {        it.extendsFrom commonFunSdkDeBUGCompile    }    // Establish release compile dependencIEs for build variants    [funappReleaseCompile, funappbetaReleaseCompile].each {        it.extendsFrom commonFunSdkReleaseCompile    }    // Common AndroID and JUnit testing dependencIEs (JUnit tests can be run    // using only a JVM; AndroID tests require a device or emulator)    [androIDTestCompile, testCompile].each {        it.extendsFrom commonTestCompile    }}dependencIEs {    commonFunSdkDeBUGCompile project   (path: ':fun-sdk', configuration: 'deBUG')    commonFunSdkReleaseCompile project (path: ':fun-sdk', configuration: 'release')

我的库gradle文件看起来像:

apply plugin: 'com.androID.library'androID {    compileSdkVersion 25    buildToolsversion '25.0.2'    publishNonDefault true // <-- This happened to be the key component    packagingOptions {        exclude 'meta-inf/liCENSE.txt'        exclude 'meta-inf/NOTICE.txt'    }    defaultConfig {    }    buildTypes {        deBUG {        }        release {        }    }}configurations {    deBUG    release}dependencIEs {    compile filetree(include: ['*.jar'], dir: 'libs')
总结

以上是内存溢出为你收集整理的Android Studio库项目引用解析符号全部内容,希望文章能够帮你解决Android Studio库项目引用未解析的符号所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1118176.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存