Archinamon / android-gradle-aspectj

gradle plug-in adding supports of AspectJ into Android project
Apache License 2.0
363 stars 58 forks source link

Please, help #112

Open Adm123Git opened 4 years ago

Adm123Git commented 4 years ago

Please, help me..! I'm newbie in android...

My project gradle.build:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath 'com.archinamon:android-gradle-aspectj:4.1.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

My app gradle.build:

apply plugin: 'com.android.application'
apply plugin: 'com.archinamon.aspectj'

android {
    compileSdkVersion 29
    buildToolsVersion '29.0.3'
    defaultConfig {
        applicationId 'com.example.test'
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName '1.0.0'
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
    productFlavors {
    }
}

dependencies {
.........................
}

Pjoject compiling normal. Try start on device and... Method com/archinamon/api/ClasspathFileCollection.getBuildDependencies()Lorg/gradle/api/tasks/TaskDependency; is abstract

What can I do?

MatthewBerk commented 4 years ago

My setup is probably not the proper way, I have not really messed around with it yet since it currently "works" for what I am doing. I designed it based off of another post discussing issue with newer versions of this plugin which is why I am using 3.4.0. One major problem I always run into is after 5 or so builds/rebuilds, I need to invalidate caches and restart IntelliJ due to Archinamon files still being used. Probably due to my build.gradle setup.

My app build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.archinamon.aspectj'
buildscript {
    repositories {
        google()
        maven { url "https://jitpack.io" }
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "com.archinamon:android-gradle-aspectj:3.4.0"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.aspectideaone"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions{
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation project(':coupleaspects') //android library with my aspects
    implementation 'com.google.android.material:material:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

aspectj {
    includeAspectsFromJar 'coupleaspects'
    debugInfo true
    ajcArgs << '-referenceInfo' << '-warn:deprecation' << '-verbose'
} 

My android library build.gradle

apply plugin: 'com.android.library'
apply plugin: 'com.archinamon.aspectj-provides'

buildscript {
    repositories {
        google()
        maven {url "https://jitpack.io" }
        mavenCentral()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "com.archinamon:android-gradle-aspectj:3.4.0"
    }
}

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions{
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

aspectj {
    debugInfo true
    ajcArgs << '-referenceInfo' << '-warn:deprecation' << '-verbose'
}

Didn't put anything in project build.gradle file.

Hope this helps.

Adm123Git commented 4 years ago

MatthewBerk, tnhank you! I'll try it soon

rahuljain88 commented 4 years ago

Update your gradle-wrapper.properties file with below version.

distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

m0skit0 commented 4 years ago

Setting Gradle to 6.3 and min SDK to 24 solves this error.

jdvp commented 4 years ago

@Adm123Git did any of the above suggestions work for you? if so, please mark this issue as resolved

cyangibm commented 4 years ago

Hi, My project requires minSDK = 16, which version of the plugin should you use?

Thanks!

Archinamon commented 3 years ago

Hi, My project requires minSDK = 16, which version of the plugin should you use?

Thanks!

Hi! At least you have to use corresponding version of gradle and aspectj plugins. You may use aspectj 4.1.0 with Gradle 6.3+ and AndroidGradlePlugin 3.6.+ Or, aspectj 4.2.0 with Gradle 6.3+ and AndroidGradlePlugin 4.0.+

No other requirement on minSdk should not affect your build.