DSpotDevelopers / declex

DecleX - Declarative Framework for Android, easier and faster coding.
Other
168 stars 25 forks source link

ActionBarActivity deprecated in support library 26+ #244

Closed email4shahbaz closed 5 years ago

email4shahbaz commented 5 years ago

I created an app using awesome feature of your framework. In order to add braintree drop-in (for paypal) I needed to change compile version from 25.2.3 to 28.0.0 in build.gradle file.

All of a sudden build process is failed due to fact that ActionBarActivity is not supported in 28.0.0. I digged down into code and found following code which is throwing error in all my fragment actionholders.:

void init(String tag) { this.tag = tag; builder = AddRecipeFragment_.builder(); if (context instanceof AppCompatActivity) { transaction = ((AppCompatActivity) context).getSupportFragmentManager().beginTransaction(); } else { if (context instanceof ActionBarActivity) { transaction = ((ActionBarActivity) context).getSupportFragmentManager().beginTransaction(); } } }

Can you please remove ActionBarAcitivty reference or do something to save my life?

email4shahbaz commented 5 years ago

image

smaugho commented 5 years ago

Hi @email4shahbaz . I think we solved this issue in our internal build. But it is a alfa-build of DecleX 2.0, there are several changes (and many new features)... So, probably you will have issues migrating, though I could help you on it.

You should add DecleX like this:

    //Declex dependencies
    annotationProcessor 'com.dspot:declex:2.0.a.23'
    implementation 'com.dspot:declex-api:2.0.a.23'
    implementation 'com.dspot:declex-actions:2.0.a.21'

About Build Tools 28.0.0, we are using in most of our projects right now 27.0.3. Though I'll make on these day a full test of all the framework on 28.0.0 with the last gradle plugin.

We should definitely make a migration guide for Declex 2.0-beta.. I'll start working on it.. probably, it will be mainly to reference the Annotations in a different package.

Please keep me updated, I'll help as much as possible with the issue.

email4shahbaz commented 5 years ago

Dear @smaugho . Thank you so much for your swift response. I have started migration by using DecleX 2.0 build links you mentioned above. However I am facing one issue at this point as follows:

I cannot use "User" implementation in any model. If I put under-square ( ) next to any model call, it still throws error. Can you please help me in this regards?

email4shahbaz commented 5 years ago

Can you please send me some quick migration rules/hints?

smaugho commented 5 years ago

Sure @email4shahbaz. The issue it is probably because the framework is not compiling the class User.

Firstly, you should ensure that each one of the annotations related to Declex is pointed correctly to their current package.

Several annotations changed the package, so probably if you go to your User class, the Annotations are not correct.

The faster solution is to remove from all the "includes" in the top of the file, anything related to DecleX, then you should import (Alt+Enter in Android Studio, then Optimize Import) every one of the annotations belonging to Declex.

You can then check what changed exactly, and to avoid doing this for every single file, you can replace completely the "include line" of the changed annotations, by another.

If you're able to post me more of your code, I can definitely help you with it, so that you see the things that were changed on it after I fix it.

email4shahbaz commented 5 years ago

Thanks @smaugho I have postponed migration to weekend because I needed to complete an important feature in my application. I will definitely ask you questions during the migration process.

However I have one question: Can we put @Model inside android Service?

smaugho commented 5 years ago

You you could insert a model, but you should declare the service using AndroidAnnotation @EService or @EIntentService.. more information here:

https://github.com/androidannotations/androidannotations/wiki/Enhance-services

https://github.com/androidannotations/androidannotations/wiki/Enhance-IntentServices

email4shahbaz commented 5 years ago

@smaugho I have spent whole day on migration. It was NOT an easy task. lot of pain. At the end, i am stuck with following error messages:

Processor "com.dspot.actions.processors.PutModelActionProcessor" couldn't be loaded: com.dspot.actions.processors.PutModelActionProcessor  
Processor "com.dspot.actions.processors.PopulateActionProcessor" couldn't be loaded: com.dspot.actions.processors.PopulateActionProcessor  
Processor "com.dspot.actions.processors.LoadModelActionProcessor" couldn't be loaded: com.dspot.actions.processors.LoadModelActionProcessor  
Processor "com.dspot.actions.processors.RecollectActionProcessor" couldn't be loaded: com.dspot.actions.processors.RecollectActionProcessor  
Processor "com.dspot.actions.processors.LoadModelActionProcessor" couldn't be loaded: com.dspot.actions.processors.LoadModelActionProcessor  
Processor "com.dspot.actions.processors.PutModelActionProcessor" couldn't be loaded: com.dspot.actions.processors.PutModelActionProcessor  
Processor "com.dspot.actions.processors.PopulateActionProcessor" couldn't be loaded: com.dspot.actions.processors.PopulateActionProcessor  
Processor "com.dspot.actions.processors.RecollectActionProcessor" couldn't be loaded: com.dspot.actions.processors.RecollectActionProcessor  
Processor "com.dspot.actions.processors.PutModelActionProcessor" couldn't be loaded: com.dspot.actions.processors.PutModelActionProcessor  
Processor "com.dspot.actions.processors.LoadModelActionProcessor" couldn't be loaded: com.dspot.actions.processors.LoadModelActionProcessor  
Processor "com.dspot.actions.processors.PopulateActionProcessor" couldn't be loaded: com.dspot.actions.processors.PopulateActionProcessor  

Please help me.

smaugho commented 5 years ago

Hi @email4shahbaz , sorry for it.. since some packages changed I guess it makes it difficult.. About that error above, could you check this:

Use this version of the Gradle Android plugin:

classpath 'com.android.tools.build:gradle:3.1.4' 

compile for SDK 27 (or lower):

    compileSdkVersion 27
    buildToolsVersion "27.0.3"

ensure to declare the 3 dependencies:

    annotationProcessor 'com.dspot:declex:2.0.a.23'
    implementation 'com.dspot:declex-api:2.0.a.23'
    implementation 'com.dspot:declex-actions:2.0.a.21'

We haven't fully tested everything for the last gradle plugin and BuildTool 28, I'm just thinking that could be an issue in your case, but not sure, please if possible share with me your gradle configurations.

Thanks!

email4shahbaz commented 5 years ago

my gradle configurations are as follows:

apply plugin: 'com.android.application'

android { compileSdkVersion 28 defaultConfig { applicationId "com.beaconwatcher.myneads" minSdkVersion 23 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    //Very Important to fix error: Could not find the AndroidManifest.xml file, using generation folder
    javaCompileOptions {
        annotationProcessorOptions {
            arguments = [
                    'androidManifestFile': 'app\\build\\intermediates\\merged_manifests\\debug\\processDebugManifest\\merged\\AndroidManifest.xml'
            ]
        }
    }

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

}

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0-alpha1' implementation 'androidx.constraintlayout:constraintlayout:1.1.0' implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:preference-v7:28.0.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha1'

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

 implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
 implementation 'com.android.support:design:28.0.0-alpha1'
 implementation 'com.android.support:support-v4:28.0.0-alpha1'

 implementation 'com.android.support.constraint:constraint-layout:1.1.0'
 implementation 'com.google.android.material:material:1.0.0-alpha1'

 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'*/

//Declex dependencies
annotationProcessor 'com.dspot:declex:2.0.a.23'
implementation 'com.dspot:declex-api:2.0.a.23'
implementation 'com.dspot:declex-actions:2.0.a.21'

implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.0'

implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-database:16.0.3'
implementation 'com.google.firebase:firebase-storage:16.0.3'
implementation "com.google.firebase:firebase-auth:16.0.4"
implementation 'com.google.firebase:firebase-messaging:17.3.3'

implementation 'com.github.bumptech.glide:glide:3.7.0'

implementation 'com.facebook.android:facebook-android-sdk:4.6.0'

}

smaugho commented 5 years ago

Thanks!

Could you please compile for compileSdkVersion 28, and the provided Gradle plugin (you should see that one in the project build.gradle).

email4shahbaz commented 5 years ago

sure, let me try

email4shahbaz commented 5 years ago

is there any basic/startup project to be used as template? can you send me a basic project with all configurations set. So that I can use that and start my project from scratch by just copying my files inside it?

smaugho commented 5 years ago

I created a new branch in the project "Ready To Start" which is configured with the last version we are using of DecleX:

https://github.com/smaugho/declex-example-ready/tree/declex_2

email4shahbaz commented 5 years ago

Thank you so much for the new branch. I will definitely will try to use it. I have one little confusion:

In last version we could load/put a model using $PutModel action. Has it changed in new version or we can use it same way?

I see few new action classes (i.e PutModelActionProcessor and LoadModelActionProcessor). Can you please describe how can we load/put data into model?

email4shahbaz commented 5 years ago

in one of my existing project which I migrated, $PutModel and $LoadModel are not resolved. It show error message "Cannot resolve symbol "$PutModel". Same for $Toast action. Can you please suggest what to do?

smaugho commented 5 years ago

This is something strange. On that class, include statically those methods (typically you can simply Ctrl+Enter -> Import static method...)

image

You could also add it manually, please test this, add them in the includes section:

import static com.dspot.declex.actions.Action.$LoadModel;
import static com.dspot.declex.actions.Action.$PutModel;
import static com.dspot.declex.actions.Action.$Toast;
email4shahbaz commented 5 years ago

@smaugho Thanks again for your great help. I am slowly progressing in Migration. Actually my project has almost 150+ classes and 50+ models. You "Ready to Use" code help me.

I am struggling with one issue at the moment:

There was an annotation "@Extension" which was being used in BaseModel class. I am unable to find it in the framework, it was imported previously with following import:

import com.dspot.declex.api.extension.Extension;

Can you please help me find that annotation?

smaugho commented 5 years ago

This annotation was deprecated. Please, simply replace it by @UseModel on base classes.

email4shahbaz commented 5 years ago

Thanks, it worked.

email4shahbaz commented 5 years ago

@smaugho . Thanks for all your help but unfortunately I am stuck at one more issue. I have started a project from scratch using your "Ready to Start" project.

Issue is: I have successfully created an activity which uses common annotations. But when I add $Toast or $PutModel it shows error messages as follow:

image

If i remove "$Toast" or "$PutModel" these errors vanish and build it successful. Please help me solving this issue.

email4shahbaz commented 5 years ago

Related to my previous comment ($Toast or $PutModel throws multiple errors). Can you please add some example code in your Ready To Start example for load/put model data from server?