代码之家  ›  专栏  ›  技术社区  ›  Alexei

AndroidAnnotions:在发行版中,BuildType找不到符号

  •  0
  • Alexei  · 技术社区  · 6 年前

    andoid工作室3.2.1 等级4.1

    在调试模式下,项目具有 applicationId "com.myproject" . 在发布模式下,project有“applicationid”com.myproject.beta

    在我的项目/build.gradle中:

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    

    在我的app/build.gradle中:

      apply plugin: 'com.android.application'
    
       android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.myproject"
            minSdkVersion 15
            targetSdkVersion 28
            versionCode 1
            versionName "1.1.1"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    
        }
    
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
        }
    
        signingConfigs {
            release {
                keyAlias keystoreProperties['KEY_ALIAS_RELEASE']
                keyPassword keystoreProperties['KEY_PASSWORD_RELEASE']
                storeFile file(keystoreProperties['STORE_FILE_RELEASE'])
                storePassword keystoreProperties['STORE_PASSWORD_RELEASE']
            }
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                signingConfig signingConfigs.release
                configBuildType(delegate, "Release instance", "Release app name", "beta")
            }
            debug {
                configBuildType(delegate, "Release instance", "Release app name", null)
                ext.betaDistributionReleaseNotes = defaultConfig.versionName + " " + name
                ext.betaDistributionEmailsFilePath = "app/beta_distribution_emails.txt"
            }
        }
    
    } 
    
    def configBuildType(buildType, instanceName, appName, appIdSuffix) {
        buildType.resValue("string", "app_name", appName)
        buildType.applicationIdSuffix(appIdSuffix)
        buildType.buildConfigField("String", "INSTANCE_NAME", instanceName)
    }
    
    def AAVersion = '4.5.2'
    
    dependencies {
        annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
        annotationProcessor "org.androidannotations:ormlite:$AAVersion"
    
        implementation fileTree(dir: 'libs', include: ['*.jar'])
    
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support:animated-vector-drawable:28.0.0'
        implementation 'com.android.support:exifinterface:28.0.0'
        implementation 'com.android.support:cardview-v7:28.0.0'
        implementation 'com.android.support:customtabs:28.0.0'
        implementation 'com.android.support:support-media-compat:28.0.0'
        implementation 'com.android.support:support-v4:28.0.0'
    
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        implementation 'org.apache.commons:commons-lang3:3.8.1'
        implementation 'org.apache.httpcomponents:httpclient:4.5.6'
        implementation 'com.google.android.gms:play-services-gcm:16.0.0'
        implementation 'com.google.code.gson:gson:2.8.2'
        implementation 'com.j256.ormlite:ormlite-android:5.1'
        implementation 'commons-io:commons-io:2.6'
        implementation "org.androidannotations:androidannotations-api:$AAVersion"
        implementation "org.androidannotations:ormlite-api:$AAVersion"
    
        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'
    }
    

    如您所见,我使用android注释库:

    org.androidannotations:androidannotation:4.5.2'

    当我选择 buildType = debug 项目成功建立。

    但当我选择 buildType = release 我得到错误:

    :scanlib:transformClassesAndResourcesWithPrepareIntermediateJarsForRelease UP-TO-DATE
    :app:javaPreCompileRelease UP-TO-DATE
    D:\myproject\app\activity\DebugConfigActivity.java:29: error: cannot find symbol
    import com.myproject.app.widget.DebugRuleWidget_;
                                ^
      symbol:   class DebugRuleWidget_
      location: package com.myproject.app.widget
    

    此处活动:

    import org.androidannotations.annotations.EActivity;
    import com.myproject.app.utils.AndroidUtil;
    import com.myproject.app.widget.DebugRuleWidget_; // error here
    
    @EActivity
    public class DebugConfigActivity extends AppCompatActivity ..
    }
    
    import org.androidannotations.annotations.EView;
        @EView
        public class DebugRuleWidget extends LinearLayout implements ContextMenuInfo {
        }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   WonderCsabo    6 年前

    添加此块:

    android {
        defaultConfig {
            javaCompileOptions {
                annotationProcessorOptions {
                    arguments = ["resourcePackageName": android.defaultConfig.applicationId]
                }
            }
        }
    }