This is the library I am using. But I need to change the style java code. But since it's an external dependency, the file is read-only.
I learned here that if I add it as module I can then edit the file. I did that. I added the module successfully.
But now, the problem is how do I use the class from the library module. For instance, in my MainActivity.java, when I declared the global variable CarouselPicker carousel, Android Studio said 'Cannot resolve symbol CarouselPicker' and there is no Alt+Enter option to import any class. CarouselPicker is a class in the library. It worked when I used the library using compile in dependencies.
EDIT:
This is my Android file structure:
screenshot of Android file structure
This is the dependencies block code of my build.gradle(Module:app):
screenshot of code bloack
In my Share.java file, I tried to import CarouselPicker, this is what I get for Alt+Enter:
What Alt+Enter gave me.
please make sure that you have added the dependency line of the module in the gradle
see this for more details How to import class from another module in android studio?
Related
I am having an unresolved class error in my manifest file and I do not quite understand why. If I try to refer to the class, Android Studio suggests me the correct class but when I select it it shows me unresolved class error. The class is inside of a base package inside of AndroidTest folder.
What could be the issue here? I read that I might be missing some line in my build.gradle file to include the corresponding classes inside of the build path, but I am not sure how to add this?
Android Manifest File, suggestion being made by Android Studio:
Android Manifest File, no class found error when adding suggestion to manifest file:
This is my current build.gradle file:
I am preparing a Gradle build script for my Android application. Before build task starts I've to change main class name and thus change imports in each *.java file.
For example, if now my main class is com.company.myApp, so the packages in each java file are imported in following way: import com.company.myApp.pacakge.* and when I rename main class to com.company.newName I've also to change imports to: import com.comapny.newName.package.*.
I am beginner with Gradle but I was trying to find information about equivalent of replace() function and I found shadow plugin but it works on JAR files. There is one more soultion which is using ReplaceTokens but it works with tokens and class name is not a token like.
Is there any way to do it with Gradle?
For others with similar issue, changing any string to other using Gradle is quite easy. I've resolved my problemu using:
copy {
from "src_tmp"
into "src"
filter {
String line -> line.replaceAll("com.company.app", "com.new.string")
}
}
I'm using CSipSimple. I followed the migration guide from Eclipse to Android Studio carefully and the only error that I am getting is
cannot resolve symbol utils
and is happening on below lines:
import com.actionbarsherlock.internal.utils.UtilityWrapper;
import com.csipsimple.R;
In build.gradle, I have added the following line:
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:19.0.+'
}
Does anyone know why this would be happening? Any suggestion will be of great help.
ActionBarSherlock-4.4 does not have the package utils.
Check the version that was used before migrating to Android Studio.
VenomVendor's answer already provides the reason: there's no UtilityWrapper on ActionBarSherlock. So, I'll try to provide the fix instead.
tqcenglish has a GitHub repo for Android Studio port for CSipSimple. Its readme says:
Change
/res/values/wizard_sipgate_string.xml
<string xm:lns:ns0="http://schemas.android.com/tools" /> -
<resources xmlns:ns0="http://schemas.android.com/tools"/> +
delete jni folder
add jniLibs folder and org.pjsip.pjsua to java folder
delete about quote UtilityWrapper
Reference
com.actionbarsherlock:actionbarsherlock:4.4.0#aar
This seems to give a hint of removing any reference to UtilityWrapper, including import com.actionbarsherlock.internal.utils.UtilityWrapper;. However, it might compromise something.
You're on the right path to use com.actionbarsherlock:actionbarsherlock:4.4.0#aar for the dependency.
Alternatively, I don't see any reasons why files under utils won't work outside of com.actionbarsherlock.internal package, so you should be able to copy all files from com.actionbarsherlock.internal.utils to your java folder, then replace the import statement to use the corresponding package.
If you get this error while trying to use OpenCV, import this:
import org.opencv.android.Utils;
when I try to integrate with my friend android-project and need to import my libs folder however the application start to have "errror:cannot find symbol method getContext". Anyone got idea what is happening ?
When I remove these code , the file will work properly. However my another project when import these libs doesn't have any problem.
dependencies {
compile files('libs/android-support-v4-r13.jar')
compile files('libs/indoors-library-surface.jar')
compile 'com.google.guava:guava:12.0'
}
Please check your directory structure or post your code might be you missing something that not letting you to build gradle
I created an Android project and imported a library using its source code. I added it as an existing module.
When my project referenced a library class, the IDE offered me to import the package. It did it without problem. I compiled the library and it was okay.
I used this import:
import eu.janmuller.android.simplecropimage.CropImage;
When I compiled again, the source code shows no errors, yet I get these errors:
java: package eu.janmuller.android does not exist java: package
eu.janmuller.android.simplecropimage does not exist
So the IDE offered me the package as it knows it. On second thoughts, it does not.
What should I set?
I renamed the imported module once so when I restarted the IDE, it was marked with a number (CropImage1) but it compiles now. If I rename it again, it won't compile.
NEVER rename anything when dealing with modules!