Module interface not updated - android

I have a library which I use in several projects.
In this library I have a function like:
public boolean update(Context context, String name,
UpdateResponseCallback callback)
throws firstException {
Now I want to change this firstException to secondException (or to the general Exception or whatever). The build of the library works okay. And also the generated files appears to be okay.
When I move to the App which includes this library things go wrong.
The compiler does not recognise the new/updated format. Also the quick help (mouse over) give the old interface.
I have already performed CLEAN and also File:InvalideChache but nothing helps.

Related

Various questions #NonNull, #NotNull and #ParametersAreNonnullByDefault

I'm an Android dev who is using AndroidStudio or IntelliJ IDEA.
I tend to trust my IDE and I'm annoyed with next facts:
In android project when IDE autogenerates a method in java that extends Kotlin class then both IDE uses #NotNull instead of #NonNull, is there setting for this? This
We have #ParametersAreNonnullByDefault but when I override the method from the point 1 and I don't put any annotation IDE warns me, but why?
Am I wrong in my assumptions?
Are there solutions?
Which annotations to use for null/not-null is set under Configure annotations... in the Compiler page of the Settings/Preferences dialog. Select the one you want and press the checkmark button. See https://www.jetbrains.com/help/idea/nullable-notnull-configuration-dialog.html for documentation.
I can't test right now whether IDEA/AS use the default annotations from there when overriding a method which already uses another, but if they don't you'll need to file a ticket.

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

Android AOSP Contacts app and Calls.VOICEMAIL_TYPE

Im trying to build the Contacts app from AOSP as a Android project in Eclipse. I can't find the reference
Calls.VOICEMAIL_TYPE
in code CallLogFragmentTest.java
private void insertVoicemail(String number, long date, int duration) {
Object[] values = getValuesToInsert(number, date, duration, Calls.VOICEMAIL_TYPE);
// Must have the same index as the row.
values[CallLogQuery.VOICEMAIL_URI] =
ContentUris.withAppendedId(VoicemailContract.Voicemails.CONTENT_URI, mIndex);
insertValues(values);
}
Even in my other Android environment the variable VOICEMAIL_TYPE does not exist?
Has someone done this, if so exactly what libs did you use?
VOICEMAIL_TYPE is found in CallLog.Calls, as you can see from the source.
Here are two reasons I can think of for why you are missing this:
You do not have all the right source code (i.e., your copy of CallLog does not have VOICEMAIL_TYPE)
You actually set up an Android project (with an android.jar as part of your build path), as VOICEMAIL_TYPE is marked as #hide, so while it is part of an OS build, it is not part of the Android SDK
There may be other reasons as well.
CommonsWare pointed me out in the right direction and I solved it by building the AOSP and then I got out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar and added it first in my build path in Eclipse

Handling a core project and multiple derived from it in Android

I've searched around SO for this and found a few things, but I'm still not sure I fully understand, so I ask you for clarifications.
Here is what I need:
Have a project that has specific function: interrogate web service, display results in different views
Have a second, third and forth project that has exactly the same functionality as the first one, but only different graphic elements like splash screen image, icon, name, package name.
So, I have ProjectCore with activities and functionality. Project1 with a car icon and car image for splashscreen. Project2 with airplane icon and airplane image for splashscreen. Something like that. Each projects has a class with constants like'appId, appName, appServerURL"... All the web service call, data display is in Core as it's the same for all prohects, only the read is made from Constants class.
I was thinking of this approach
Make ProjectCore a Library project with a package like com.domain.core and dummy images
Make Project1, add reference to ProjectCore in it and with a package like com.domain.code.project1 and in resources folder, put images with same name as in core project
Make Project2 on the same principle like project1
Will this approach work ?
Thanks.
Later Edit. I've tried as mentioned before. For instance in Core project I had in drawable a file called splash.png. In Project1's and Project2's drawable folder I've put spash.png file with other images. This works fine. Running the Project1 and Project2 on my phone, started each app with it's own image. So far so good.
Then, because I have different constants I need to use in my App, I went into Core library project and added:
public class C {
public static String SomeConstant = "Project core!";
}
Here comes the problem, I need to have different constant values across Project1 and Project2. Because on Core project, the class is in com.domain.core.utils for instance... I can't add the same package in Project1 and Project2. How do I add the classes so I can update their values and be used on each project with particlar values ?
public class C {
public static String SomeConstant = "Project 1 constant!";
}
public class C {
public static String SomeConstant = "Project 2 constant!";
}
Thank you!
You want to create your functionality in a Library project and then have all of your Branded/OEM/3rdParty projects extend from this, overriding images and string resources where necessary.
When you need to use "Constants" you should instead have a single "run once" portion of your code (such as a splash screen) load these strings from resource files:
public static final String CONSTANT_ONE;
public void onCreate() { CONSTANT_ONE = getResources().getString(R.String.CONSTANT_ONE); }
EDIT
I'm unsure on how initialising a final value on onCreate() will perform. If final doesn't work well and you're worried about changing the variable during program execution then make the variable private (so only that class can assign to it) and then create a public static String getConstantOne() function.
Yes. Library projects are ideal for this, especially if only resources differ. I've used the exact approach that you've outlined with success...
Yes this should work fine. I did something a bit similar and I found occasionally you may have some circumstances where you want to call out from your library project to your application project. In these cases I used interfaces/abstract classes defined in the library project but implemented in application project...

Android using AndroidAnnotations in Library Project Eclipse

I'm making a paid/free version of my app so have a 'Library Project' that the two apps use.
I'm trying to use Android Annotations to clean up my code:
http://code.google.com/p/androidannotations/
Unfortunately when I use this in my shared library project, one of my projects gets the error in Eclipse:
The type xActivity_ is already defined xActivity_.java /ProjectName/.apt_generated/lib/activities/
Because Android Annotations automatically creates a new activity with an extra '_' in the folder .apt_generated one of the apps is allowed to create this file, but the other gets the error "already defined".
Is there a way in Eclipse to resolve this? Or is it a problem with the Android Annotations?
This seems to be an AndroidAnnotations bug, and should be reported on the dedicated bug tracker.
AndroidAnnotations wasn't designed with this use case in mind, but this is still a very valid use case. The problem seems to be that the activity is generated in the shared library project, when it should be generated in each depending project, am I right ?
(please answer in the bug tracker)
This question is quite old, but I thought that I should mention android annotations now supports being used in libaries:
https://github.com/excilys/androidannotations/wiki/Library-projects
One caveat is that due to the way android library projects generate the R class, you cannot reference resouces directly inside the annotations. Eg, you cant do this:
#EActivity(R.layout.myLayout)
public class MyActivity extends Activity {
#Click(R.id.myButton1, R.id.myButton2})
public void someButtonClicked() {
}
}
Instead you must do this:
#EActivity(resName="myLayout")
public class MyActivity extends Activity {
#Click(resName={"myButton1", "myButton2"})
public void someButtonClicked() {
}
}
I just knew AndroidAnnotations (which seems a great tool!) but I think that if you do this using different projects (sharing the same library) your problem should be solved.

Categories

Resources