The hierarchy of the type MainActivity is inconsistent - actionbarsherlock

I created a new Android project via eclipse, with a MainActivity.
I added ActionBarSherlock to the project (Properties > Android and clicked Add).
Then, when I replace "extends Activity" with "extends SherlockFragmentActivity" I get a compile error "The hierarchy of the type MainActivity is inconsistent".
I also tried to create a project without an Activity, then created a class "MainActivity" that inherits from SherlockFragmentActivity, and there are no compile time errors, but with a run-time error "ClassNotfoundException: com.NadavLitvak.nadavfragmentdemo.MainActivity"

Your project should also reference the android-support-v4.jar (which is included in ABS's libs folder.) So, Properties->Java Build Path->Add JARs... and select that jar from ActionBarSherlock->libs

Sometimes, when Eclipse gets retarded, it doesnt add the SDK jar in your project (the Android x.y folder missing in project) so then you need to add it Properties > Android > Project Build Target (usually nothing there is ticked)

Related

Hide Gradle pre-compiled plugins generated sources in Android Studio

I have a gradle pre-compiled script plugin inside the build-logic project, which I use as an included build on android-project. The Android project tree view displays also the generated sources for some-plugin which I want to hide.
With this default setup, AS can resolve a reference for the extension detekt because is a generated accessor.
I can hide the generated sources by applying the idea plugin to some-plugin and excluding the generated-sources directory as follows:
// build-logic/settings.gradle.kts
gradle.beforeProject {
pluginManager.apply("idea")
configure<org.gradle.plugins.ide.idea.model.IdeaModel> {
module {
// Exclude generated sources from AS project tree
excludeDirs = setOf(
file("${buildDir}/generated-sources/kotlin-dsl-plugins/kotlin"),
file("${buildDir}/generated-sources/kotlin-dsl-accessors/kotlin"),
file("${buildDir}/generated-sources/kotlin-dsl-external-plugin-spec-builders/kotlin")
)
}
}
}
Which effectively now take away the generated sources from the Android view:
But as you can see, the detekt extension is not longer resolved by AS. Build compiles successfully.
How can I hide the generated-sources files but still allowing AS to resolve references to the hidden files?
You can create your custom files scope and even associate with a color where you can exclude the needed directories and set it for the Project tool window.

AndroidStudio preview class not found org.json.JSONObject

I work with Android Studio 2.1.1. I am writing a class which extends LinearLayout. This class has a string attribute which I try to parse with basic android JSON lib in the class constructor. The code seems fine as it compiles and installs to the device. But Android Studio cannot find the class in the Preview (see screenshot below).
What is the solution of problem?
How do I set 'JSON lib' of Android Studio Preview?
Android Studio Screenshot
Android Studio error stack:
java.lang.ClassNotFoundException: org.json.JSONException
at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:154)
at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:52)
at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483)
at java.lang.Class.getConstructor0(Class.java:2793)
at java.lang.Class.getConstructor(Class.java:1708)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:396)
at ...
Using Android Studio 2.2.3, I had the same problem, and sky's workaround worked for me, but I looked deeper and discovered the ClassNotFoundException was caused specifically by a reference to JSONException in code not ever executed in the view draw code needed for the layout preview. Interestingly, non executed references to JSONObject do not cause a ClassNotFoundException, but apparently the compiler wants to load the JSONException class regardless.
My solution was to catch Exception instead of JSONException in my code (which would be unaffected by the change). I decided this was preferable to adding the otherwise unnecessary library.
I did found only the WORKAROUND for this kind of issue. I did download 'json-20160212.jar' from maven repo. Then placed it to project's root directory (or other directory you like), and did add the dependency in project's build.gradle:
dependencies {
provided files('json-20160212.jar')
}
I'm using 'provided' scope to avoid json library been compiled with my project, but have an ability to 'preview' my layout without ClassNotFoundException.

ProGuard issues with Android Archieve(.aar) library

I've a library project which I want to distribute, in AAR format. I've applied ProGuard on it.
ProGuard settings works well if I use this lib as a module, but not when I use resulting AAR. Basically it fails with exception "java.lang.IllegalArgumentException: already added Lmy/lib/package/name/R;" in Application project.
ProGuard is renaming one of my lib class to R, and I feel which is causing problem in Application project as R is used for Resources.
How do I specify proguard mapping in Studio to tell it not to rename to R.
Update:
after adding AAR file as a new module, am getting this error:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lmy/lib/package/name/R;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Okay then, answering myself.
Tried running ProGuard manually on .aar, worked with latest version v5.2.1. Didn't work with default version v4.7 which came with Studio v1.2.2. Hope this helps.

From Eclipse to Android Studio: Why is proguard.cfg used when NOT building Release?

So, I have been trying to migrate the development of a multi-project (eclipse projects that is) app to Android Studio (v1.1).
Importing via File > Import Project was really easy and went without incident.
However, when I tried Make/Rebuild project I encountered numerous surprises. The first, not Proguard-related, had to do with source file encoding (originally in Windows-1252), but I quickly found a solution using this Windows-1252 > Reload > UTF-8 > Convert answer.
Then, "error: cannot find symbol class" for a com.comp.mod.X class of mine. I then solved it by going to the module (Android Studio module that is, previously an Eclipse project) that contains that class and added to its proguard.cfg the following:
-keep public class com.comp.mod.X
Which left me with an "error: cannot find symbol variable" for a const BB defined in the aforementioned class. I solved this by adding to the same proguard.cfg the following:
-keepclassmembers class com.comp.mod.X {
public static final boolean BB;
}
That left me with only one "error: cannot find symbol method getPreferenceX()". I solve this by adding to the same -keepclassmembers that method, so that the above now looks:
-keepclassmembers class com.comp.mod.X {
public static final boolean BB;
public static java.lang.String getPreferenceX();
}
I thought I was done, but to my dismay, when I attempted to rebuild the project, I received numerous additional errors from other modules in the project, all of the type to "error: cannot find symbol class/variable/method" and related to some proguard.cfg.
I could have continued butchering the proguard.cfg files for each and every module but at this point I am beginning to suspect that I am doing something fundamentally wrong, because those proguard.cfg files work perfectly under Eclipse. So,
Why all of a sudden these are no longer good for Android Studio?
If ProGuard runs only when you build your application in release mode, why is the Android Studio based build complaining about "cannot find symbol" due to Proguard's obfuscation?
What am I missing?
Note: I have not attempted "Generate Signed APK". All I do is "Rebuild Project".
Currently (as of 2015-04-24), minifyEnabled's default value of false for all build types is incorrect for multi-module projects, in which some modules (app included) are dependent on other modules. This is due to bug #52962 that causes build types to not propagate to libraries -- they are always built as RELEASE.
Suggestions to work around this bug or notifications of its fix are most welcome.

how to link with an extra object file?

I have a visual c++ project which compiled correctly. Myproject.vcxproj contains a1.cpp, a2.cpp.
Now I'd like to remove a1.cpp from the project and link with the previously generated a1.obj .
I have added $(SolutionDir) to VC++/Library directories
I have added a1.obj to Linker/Input/Additional dependencies
I have got the following error message
LINK : fatal error LNK1104: cannot open file 'a1.obj'
What I made wrong?
I'm using Visual C++ Express 2010.
A (relatively) clean way to do what you seem to be trying to do is to make a library in the same solution, and add it as a reference to the project that will use it.
Right click the project, select "References" then "Add new reference" and then select the library project in your solution.
If you really want to try using the linker properties, note that there is a "Additional Libraries Directory" setting - this will need to be the OutputDir of the project you are trying to import - and is different to the "Additional dependencies" library name (just the lib name without a path)

Resources