SafeArgs are not generating the needed actionclass - android

I am building a basic app. When i press a button i want to navigate to a new fragment and that fragment should have a number of items in it.
According to the documentation, Gradle should generate an inner class in my MainFragmentDirections.class, which should represent the various actions this destination has, but Gradle does not do that. Everything else works fine, so i have implemented the dependencies and plugins corretly

Try to Clean Project then Rebuild Project. I have sometimes the same problem when I add SafeArgs, this tips works for me

Related

Annotations in Application class are red, but everything is working, is it normal?

I opened the file Application.java, then on the top appeared dialog like you need to update something(I have not read properly and clicked authomatically), then every single annotation turned red denoting errorScreenshot from IDE. It seems like my app is working properly,should I leave my Application.java class in rest?
It can happen when your Android Studio loses sync with the generated code by annotations. Sometimes using gradle sync solves the issue, and in case it doesn't, try going the menu File -> Invalidate Caches/Restart

Android Studio: Does not show all errors immediately

I'm coming from Eclipse and I am used to immediate error reporting over the whole project.
Lets say I have this function:
public void test() {
//Do something
}
and I change it to
public void test(String someString) {
//Do something
}
Then eclipse would immediately highlight all classes in the project explorer, that call test() without also passing a string.
Android studio does not. It only shows it, when I happen to open such a file. Ofcource, when I compile, I will also get an error, but also only for the first file he tried to compile and failed and not for all.
I am currently in a big refactoring and this is really tedious. Compile - wait - fix one file - start over...
Am I missing someting? Not even Analyze/Inspect code... does the trick.
PS: I'm using Android Studio 2.2.3 with latest updates (24.02.2017)
Too late for you by now, but for future reference to yourself:
Instead of changing the signature of the method by adding an argument to it "manually", right click on the method, go to Refactor, go to Change Signature, in the Parameters tab click on the plus icon and add the parameter there. Now right click on the method again and select Find Usages. That will show you where you're calling the new refactored method and you can fix your code quickly.
However, to answer your question, you can see where all your errors are. Just go to Build and rebuild your project via Rebuild Project and then go the left hand side of Android Studio and change the project view to Problems
See if that helps

Change behavior of "Add new Android Components" on Android Studio

I am having a problem with my build.gradle file every time that I insert a new Fragment from AndroidStudio. When I use the tool that AndroidStudio provides to insert a new component such as fragments or activities, it creates the fragment class .java and the associated layout, but it also modifies my build.gradle, for example, my dependencies are reordered but the build.gradle file is broken after that because the order is not done properly. I attach an image with the example.
Why is it behavior happening and how could I prevent it?
I am using AndroidStudio v2.1.1 stable channel

Using another project as a library

still learning android and this is where i am stuck.
I want to use this project as a tutorial for my app
https://github.com/PaoloRotolo/AppIntro
It has a wiki, and it says i need to add gradle dependency which i'm pretty sure i'll handle properly.
Whats bothering me is how do i extend that app to my class? where do i put that project/library inside my project?
Sorry if this question is newb-ish, i tried alot of things and they didn't work.
Thank you for your help!
Since you said you'd handle adding the gradle dependence I believe you are asking how to implement an Intro screen? Did you read the How to use part on the home page of the library?
Everything is explained there. What to extend and what each method does. For the actual creation of each fragment I will give you a hint.
After creating a new class for your Intro screen, if you don't have a specific layout for your fragment just use that part of the code:
addSlide(AppIntroFragment.newInstance(title, description, image, background_colour));
where the parameters are variables that you choose. For image you could use any of your images inside the drawable folder like R.drawable.intro_ico and for background colour - ContextCompat.getColor(this, R.color.grey)
'grey' color has to be created in your colors.xml or choose anything you like.
EDIT: And if you were wondering whether you should download something and where, no you are all done only by adding these lines of code to your build.gradle. When you add them, Android Studio asks to Sync the gradle file, and then it downloads the library.
For some libraries, you'd need to download a jar file or git clone from a repository and then maybe add the downloaded folder as a Module to your project by going Android Studio>New>Import Module>locate the folder . However, for that one, adding the dependency is enough as it gets downloaded after the Sync.
it's really very simple!
you just add these lines :
repositories {
mavenCentral()
}
dependencies {
compile 'com.github.paolorotolo:appintro:3.4.0'
}
in your build.gradle file under app folder.

Shadow a part of the Fragment hierarchy

I am a newbie at robolectric unit testing, i have a fragment which i want to test, ex, ScreenAFragment. This has a hierarchy as below,
ScreenAFragment -> MyAppFragment -> MyLibFragment -> SherlockFragment.
There are 2 problems,
The MyLibFragment has some code which links to a database and does other stuff which don't need to be tested as a 'unit test case'.
This MyLibFragment reference is also causing a "PackageManager#NameNotFoundException"
How do I go about testing this? My initial thought was create a ShadowMyLibFragment and config my test case #config(shadow={ShadowMyLibFragment.class}) to use this instead of the original class. Doesn't seem to be working at the moment, as it still seems to refer to the original library and throws the old error.
Any Solutions? I am using Robolectric 2.4 version.

Categories

Resources