Consuming aars from eclipse does not work - java

*THIS PART WAS MY ORIGINAL STARTING PROBLEM. PLEASE READ THE UPDATES
I have imported an android project in eclipse that apparently depends on rengwuxian.
Since I could not find the jar and did not know how else to do it, I followed the instructions in consuming-aars-eclipse and imported a second project with the artifacts from the aar as an android eclipse project as well.
Then in my original project that I got compilation errors for com.rengwuxian.materialedittext.MaterialEditText in my layout files I added this newly created from the aar project as a reference (Project->Properties->Build Path->Add Project)
The compilation errors got resolved! But in my layout files now everywhere that is defined the element com.rengwuxian.materialedittext.MaterialEditText I get errors in the resource definitions.
Eg.the following:
error: No resource identifier found for attribute 'baseColor' in
package 'com.test
The attibute it seems to complaint about is:
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/client"
android:layout_width="match_parent"
android:layout_height="wrap_content"
.....
android:textColor="#color/text_color"
app:baseColor="#color/text_color"
app:primaryColor="#color/text_color" />
---> app:baseColor="#color/text_color"
This #color/text_color is defined in my original application in the original application's package and apparently the classes in the aar imported project (com.rengwuxian.materialedittext.MaterialEditText) can not see/access these resources.
How can I fix this? Or is there another better way for my problem?
Note: I also tried adding a source link to the folder of my project's res/ folder but did not solve this.
Update:
I removed the reference to the project and add the classes.jar to the build path (this jar was inside the aar project). Same issue
UPDATE 2:
I found this that helps to import aars to eclipse aar-for-eclipse. I copy/pasted the code snippets (task copyJarDependencies etc) in the folder but I got an exception:
No such property: libDir for class: org.gradle.api.tasks.Copy_Decorated
So I added a def in the line `libDir = new File(project.projectDir, '/libs')
Then this worked but I got:
Could not find property 'compile' on configuration container
How can fix this? I am not sure what to declare or what is missing
Update 3:
I added apply plugin: 'java' and the compile attribute is ok now but I get:
configurations.releaseCompile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
How can I fix this so that it works?
I am using this project ---> https://github.com/rengwuxian/MaterialEditText
And this post ---> http://www.nodeclipse.org/projects/gradle/android/aar-for-Eclipse

I've got a similar problem with gradle but on android studio. Solution for me was to use
configurations.releaseCompile.filter {it.name.endsWith 'jar'}.each {moveJarIntoLibs(it)}
instead of:
configurations.releaseCompile.filter {it.name.endsWith 'jar'}.each { File file -> moveJarIntoLibs(file)}
And remember not to apply java and android plugin in the same project, because it won't work (see gradle with --debug --stacktrace )

Related

IntelliJ and Android Gradle dependencies - unable to find module

I have following directory structure:
D:\PROJECT
+---javaGradleProject1
+---javaGradleProject2
+---javaGradleProject3
\---AndroidProject
| build.gradle
| settings.gradle
\---AndroidModule
build.gradle
Android module depends on all of java gradle projects that are at the same level in root directory as AndroidProject.
In AndroidProject/settings.gradle I have:
include ':AndroidModule'
include 'javaGradleProject1'
project(':javaGradleProject1').projectDir = new File(rootDir, '../javaGradleProject1')
include 'javaGradleProject2'
project(':javaGradleProject2').projectDir = new File(rootDir, '../javaGradleProject2')
include 'javaGradleProject2'
project(':javaGradleProject2').projectDir = new File(rootDir, '../javaGradleProject2')
And then in AndroidProject/AndroidModule/build.gradle I have dependencies set like this:
compile project(':javaGradleProject1')
compile project(':javaGradleProject2')
compile project(':javaGradleProject3')
This structure of dependency perfectly works and project builds when I invoke
gradle build
on AndroidProject/build.gradle.
But when I try to synchronize my IntelliJ with current gradle dependency settings I receive
Error: Unable to find module with Gradle path ':javaGradleProject1'
Error: Unable to find module with Gradle path ':javaGradleProject2'
Error: Unable to find module with Gradle path ':javaGradleProject3'
and because of that my project cannot be run from Run Configurations (it does not compile at all in IDE). I was trying to add these dependencies manually by hitting F4 and module dependencies but after synchronization all of my changes are overwritten (actually, IntelliJ just removes it).
Is there anything wrong in my gradle structure?
I have tested it on IntelliJ IDEA 14.1.4 and Android Studio 1.3.
I was able to solve this by deleting the settings.gradle file from every Gradle project that I wanted to use as dependency (clearing the contents of this file was not enough).
NOTE: As I have little knowledge of Gradle and Android Studio, I cannot provide information about why the presence of this file does not allow Android Studio to include the Gradle project as a module.
Add a colon (:) before the names of your modules when you add it in settings.gradle, e.g. for the first one, change this:
include 'javaGradleProject1'
project(':javaGradleProject1').projectDir = new File(rootDir, '../javaGradleProject1')
to this:
include ':javaGradleProject1'
project(':javaGradleProject1').projectDir = new File(rootDir, '../javaGradleProject1')
Now in addition to compiling, IntelliJ / Android Studio should give you code completion.
In my case I had to change the external module name to lowercase only.
Right click project, Select
"Configure Project Subset ..."
and select your module, rebuild your project.
Tried all the available solutions, and in last I have commented the include ':app' in settings.gradle and this resolved the issue in my case
In my case non of the answers above resolved it.
Finally, I went to settings.gradle file and inside the dependencyResolutionManagement block, I changed the repositoriesMode to "PREFER_PROJECT"
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
That was all I did and it worked like magic, maybe such can help you too, you can try it out.

TessBaseAPI cannot resolve symbol tess-two OCR Android

I am trying to run Demo App for OCR using tess-two but i am having problem with code:
I have follow these following steps:
Firstly i have downloaded and install the ndk from here https://developer.android.com/tools/sdk/ndk/index.html.
And I configured it successfully
Then I Download it "tess-two-master" from here https://github.com/rmtheis/tess-two and i extract it, in that location i run ndk-build command and it compiled successfully also.
Then i Open a completely new Android Studio project and follow these instructions https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle from section "Configure tess-two with gradle"
In the last step I go in "File -> Project Structure -> Select a module from the left subwindow -> Dependencies (last tab) ->Press the green "+" on your right -> Module Dependency -> OK"
After that i have downloaded this project https://github.com/GautamGupta/Simple-Android-OCR and I copy&paste in my new project the code in these files: "SimpleAndroidOCRActivity.java", "main.xml", "strings.xml". Of course my files had different names (in my case "MainActivity.java", "activity_main.xml", "strings.xml") so some renaming in the code was necessary.
I also opened my "AndroidManifest.xml" and I add at the end (but before "/manifest") between "/application" and "/manifest" in the just downloaded "AndroidManifest.xml" (it means that I have add it "uses-permissions" and "uses-feature" tag).
Last step I have downloaded from here https://code.google.com/p/tesseract-ocr/downloads/list the file in the english language. and in the folder of my project excatly in "app-->src-->main". I have created here a new folder and name it "assets". Inside that folder i have created another folder named "tessdata". and i put it there my .traineddata file.
Then when i am trying to sync it, i am having following error:
Warning:Dependency OCR3:app:unspecified on project tess-two resolves to an APK archive which is not supported as a compilation dependency. File: C:\Users\jana-PC\AndroidStudioProjects\OCR3\app\build\outputs\apk\app-release-unsigned.apk
When i am trying to compile it, it doesn't compile because it is showing me error that TessBaseAPI cannot resolve symbol:
My code in this part is:
import com.googlecode.tesseract.android.TessBaseAPI;
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.setDebug(true);
baseApi.init(DATA_PATH, lang);
baseApi.setImage(bitmap);
String recognizedText = baseApi.getUTF8Text();
baseApi.end();
Anyone with some help, i would be very grateful !!
Have you tried this solution: https://coderwall.com/p/eurvaq/tesseract-with-andoird-and-gradle
To use the tess-two api, you must first add this line to your app:gradle file in you android project
compile 'com.rmtheis:tess-two:7.0.0'
Add this line and sync the project again and I'm sure your problems will be solved.
Gradle dependency management is what helped me out;
I was getting unresolved symbols when attempting to import tess-two;
I experienced unresolved symbols during import of tess-two to an android as well.
Figured out that i had to import tess-two as a 'Gradle Project', not as an
'Android .aar' or as an 'Android library'; This meant i had to choose the top-level project-level directory of the tess-two project as the import directory, rather than individual sub-project 'tess-two' within the tess-two project;
Finally determined that gradle syncs the tess-two project by use of gradle build file at the project level of tess -two; But if you import
the tess-two subprojects, the project-level gradle.build of tess-two never fully
resolves the dependencies underneath the tess-two project; Hope this helps;

Error "No resource identifier found for attribute 'rectLayout'"

I was trying to create a new project for android wear in eclipse , but there is a problem in main layout i don't now how i can solve it , this is my main layout:
<android.support.wearable.view.WatchViewStub
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/watch_view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rectLayout="#layout/rect"
app:roundLayout="#layout/round"
tools:context=".MyActivity"
tools:deviceIds="wear">
</android.support.wearable.view.WatchViewStub>
it is give me this error :
Multiple annotations found at this line:
- error: No resource identifier found for attribute 'rectLayout' in package
'com.example.wear'
- error: No resource identifier found for attribute 'roundLayout' in package
'com.example.wear'
my project have two layouts "rect.xml" and "round.xml" and it is compile with 4.4W and target is 4.4W and also i have a copy of classes.jar in libs folder .
The code you've posted is fine. The problem here is that you have a copy of classes.jar in your /libs folder, but this is not a right way to properly use wearable-support-lib. This wearable-support-lib contains some resources that cannot be packaged inside a .jar file, so you need to import it as a "Library project" and attach it to your project just like other external libraries.
You need to go back to the wearable-1.0.0.aar file, located in relation to your sdk folder:
./extras/google/m2repository/com/google/android/support/wearable/1.0.0/wearable-1.0.0.aar
Unzip the whole wearable-1.0.0.aar file somwehere to your workspace. You will see that it looks almost like a standard android project.
Move classes.jar to /libs/classes.jar - inside this project, not to your own project.
Now you have to create new project from these files, with package name defined android.support.wearable.
Compile it with API 20 and check "Is Library" in project properties in Android tab.
Add reference to this library project from your project.
You can see more details about using wearable-support-lib in my other answer and in this great blog post (by Benjamin Cabé).
I just added the following code in the dependency section in my build.gradle of the module:
compile 'com.google.android.support:wearable:2.0.3'
compile 'com.google.android.gms:play-services-wearable:11.0.0'
What worked for me was changing this:
xmlns:app="http://schemas.android.com/apk/res-auto"
To:
xmlns:app="http://schemas.android.com/apk/com.mydomain.myapp"
Where com.mydomain.myapp is the package id of my app.
Presumably the res-auto functionality was not working in my project for some reason.
I got this problem too sometimes, in my case i solved it by rightclicking on the AppCompat map then click on refresh, do this with your projectfolder too.

Didn't find class on path: dexpathlist

Seriously, i don't know what to do to solve this problem.
My android project was working fine, until i needed to import a library with Maven. Since that, everything started to collapse.
What is happening: When i start my application, the following error appears on LogCat and android tells that my app stopped working. I've searched for this similar error here AND on the rest of the internet, but everything people did haven't worked for me.
Error:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.buscaserra/com.buscaserra.main.ActivitySplash}: java.lang.ClassNotFoundException: Didn't find class "com.buscaserra.main.ActivitySplash" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.buscaserra-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.buscaserra-2, /vendor/lib, /system/lib]]
Manifest and packages:
Build Path:
Same problem here.
What worked for me was adding android-support-v4.jar as a lib and making sure it was checked on Project properties -> Build Path -> Order & export.
It was mentioned here
I had the same problem when I moved the project folder from a Linux machine to a Mac.
What I did was:
Close the project
Remove the .iml file
Import the project using the "Create new project using existing code"
I am using IntelliJ.
Cheers.
I did the following steps to resolve the issue on Android Studio.
open file ./app/build.gradle
reduce compileSdkVersion (e.g. 22 -> 21)
click 'sync project with gradle file'
change back to the original compileSdkVersion (e.g. 22)
click 'sync project with gradle file'
recompile and it should work.
I have spent way to many hours on this stupid issue but finally got it resolved:
When creating a new project -> package name is causing this stupid dex issue to appear, must not be able to find the main activity during run time with whatever deployment assemply setup. Android Studio doesn't like some of my commonly used package names, I'm completely baffled..I think this is a pretty big bug haha
Given the following new project parameters:
Name: NotificationApp,
packageName: com.stores.business.notificationapp,
saveLocation: /home/me/AndroidStudioProjects/NotificationApp
I would get the following error:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.stores.business.notificationapp/com.stores.business.notificationapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.stores.business.notificationapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.stores.business.notificationapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.cvs.stores.myapplication-2/lib/arm64, /vendor/lib64, /system/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
My Solution
I resolved it by changing the package name to:com.notificationapp, then File->invalidate caches/Restart..hope this helps someone else haha
Do you have any required projects on the build path? Can't tell from your screen shot but check your "Projects" tab. You may have inadvertently added a Project Library as a required project instead. Remove the project from the Projects tab and then project -> properties. Click Android, add the project as a library instead here...
Make sure that any compatibility lib jars that you're using in your main project (like android-support-v4.jar) are the same versions as those used in any of the projects that your main project references.
I had this same problem and what solved it was to copy and paste the android-support-v4.jar from another library project (that my main project was referencing) and pasting it into my main project's /libs folder.
I had the same issue.
Nothing had changed except Android studio and Gradle updated since I last compiled.
I took a look at the build options under Build>Edit Build Types and noticed that the one option that was different between my project that didn't run and the ones that did work was the Minify Enable option.
I set it to false and now everything works again.
I should understand the problem by just seeing "dex errors".But it took half day to fix the issue.
I fix this by following android developers page's instruction: https://developer.android.com/studio/build/multidex.html
First add this to my gradle.build:
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Then I extend my Application class (or declare the application class in AndroidManifest.xml or override attachBaseContext() function) as instructed by the MultiDexApplication class document on the page. This have fixed my problem.

ClassNotFoundException: previously working Android Project

I had a working android project but needed to start from scratch. I copied all my source files and layout files over. There are no compilation errors but when I try to run, I get the following error.
11-27 17:21:56.793: E/AndroidRuntime(1450): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{projects.mobile.mapappproject/projects.mobile.mapappproject.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "projects.mobile.mapappproject.MainActivity" on path: /data/app/projects.mobile.mapappproject-1.apk
I am running eclipse juno and trying to run on Android 4.2. Thanks !
Rather than doing copy paste try following
1.Create an android application project
2.Delete the files which was created Eg.MainActivity and layout.
2.Right click on project name and click import ,then from File system.Go to your project directory to import the source from there
3.select that, then finish.
4.Clean and build then run
Try these
Add the Activity to AndroidManifest.xml
Is there a difference in your folder names ? For example projects.mobile.mapappproject-1 or projects.mobile.mapappproject !
I copied all my source files and layout files over.
It looks like you forgot to copy over the entries that existed in AndroidManifest.xml, however. Each Activity has an entry there and that entry is required for the framework to find and launch the UI.
I had the same problem, but I found out that a library reference path wasn't right. After I fixed that everything worked fine.
You can check this at Right-click on your project => Properties => Android -> (Library)
Just for the record in case I can help someone :
I had a project that somehow didnt work after importing it from git. I solved this by giving the name of the activity explicitly.
example:
before:
<activity android:name=".Main" [...] /> (relative)
after: <activity android:name="com.example.package.Main" [...] /> (absolute)
This may also occur if you change the manifest package and keep your relative reference (which I think is default).
In my case, following 2 steps fixed the problem
a. Setting compileSdkVersion, buildToolsVersion, targetSdkVersion to the same SDK version in build.gradle.
b. I was missing a dot in application class name in AndroidManifest.xml (Ex. android:name=".ui.ApplicationLoader")

Categories

Resources