Architecture-components-samples: build successful ,but can't running

Created on 21 May 2017  ·  20Comments  ·  Source: android/architecture-components-samples

C:\Users\pdog18\Desktop\android-architecture-components-master\BasicSample\app\src\main\java\com\example\android\persistence\db\AppDatabase.java

Error:(31, 17) 警告: Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide `room.schemaLocation` annotation processor argument OR set exportSchema to false.

AppDatabase

/*
 * Copyright 2017, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.persistence.db;

import android.arch.persistence.room.Database;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.TypeConverters;

import com.example.android.persistence.db.dao.CommentDao;
import com.example.android.persistence.db.dao.ProductDao;
import com.example.android.persistence.db.entity.CommentEntity;
import com.example.android.persistence.db.entity.ProductEntity;
import com.example.android.persistence.db.converter.DateConverter;

@Database(entities = {ProductEntity.class, CommentEntity.class}, version = 1)
@TypeConverters(DateConverter.class)
public abstract class AppDatabase extends RoomDatabase {

    static final String DATABASE_NAME = "basic-sample-db";

    public abstract ProductDao productDao();

    public abstract CommentDao commentDao();
}

question

Most helpful comment

Try to export the schema by adding this to your app/build.gradle

android {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation":
                             "$projectDir/schemas".toString()]
            }
        }
    }
}

All 20 comments

For me, it also says package com.example.android.persistence.databinding does not exist; cannot find symbol class CommentItemBinding

Try to export the schema by adding this to your app/build.gradle

android {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation":
                             "$projectDir/schemas".toString()]
            }
        }
    }
}

@wafer-li 不行啊..加上这个build.gradle不通过

Error:(47, 0) Could not find method javaCompileOptions() for arguments [build_5ysf0fcwfxj8vp2lg0uw45bf1$_run_closure1$_closure8@6b28c7e9] on object of type com.android.build.gradle.AppExtension.
<a href="openFile:C:\Users\pdog18\Desktop\android-architecture-components-master\BasicSample\app\build.gradle">Open File</a>

我试了下clean 然后还是报错,但是项目可以跑起来了

@GurpreetSK95 thanks , i see my databinding is always enable;
then i clean the project and run again,unfortunate ,error again ,but app can running on the avd, i don't know why ..it make me stupid

@pdog18 国际场合还是不说中文为好

I have no problem after adding the snippet, maybe you could try File -> Invalidate Cache / Restart.

And make sure you add it at the right place, my build.gradle as follow:

image

火钳流明。You know I am using Chinese.

Still doesn't work

Does this only happen in Windows? For me that's just a warning.

That schema thing is just a warning so cannot be the problem.
Can you try running ./gradlew asDeb --debug from command line and sharing the output?

I'm facing the same problem, just did what @yigit said, follow the output:
https://gist.github.com/dzfacts/0a02723bce4f42d0fa7bf15d375dce11

I think we can try, speak English by Chinese!!!

Error:Execution failed for task ':app:transformJackWithJackForDebug'.

java.lang.AssertionError: No yet implemented

@liuwenping828 do you solve this problem? 你解决了这个问题没

image
i have no problem after add it. I use mac os and i do not know the situation on windows.
code happy.

I am also getting the databinding classes not found after adding the this line
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha5"

@GurpreetSK95 were you able to solve this? I am also having the same issue with databinding after adding the room annotation processor

@GurpreetSK95 were you able to solve this? I am also having the same issue with databinding after adding the room annotation processor

Someone found a solution? I also have the same issue

This helped me: https://movieos.org/2017/android-room-data-binding-compile-time-errors/

I was seeing a max of 100 databinding errors, with no "real" error message. By expanding the number of messages that can be shown, check the last error and it will be a real Room compilation error! So, hopefully you can fix that error and get compilation working again :)

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xmaxerrs" << "4000"
            options.compilerArgs << "-Xmaxwarns" << "4000"
        }
    }
}

I had similar issue after adding Room in my existing application. BR errors hide the actual error in the code. I took steps below and could see the java error and once they were solved, my code worked perfectly fine

For Project gradle
Gradle Plugin Version classpath 'com.android.tools.build:gradle:3.0.1'
and Gradle verison gradle-4.1-all.zip

For app gradle
For Data binding in app.gradle
```
dataBinding {
enabled = true
version '2.3.0'
}


 App dependencies for Room
` implementation 'android.arch.persistence.room:runtime:1.0.0'`
 No Dependency for Data binding and other architectural components as of now

allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "5000"
}
}
}

defaultConfig{
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
`` After syncing my code I could actually see the Room errors instead of BR errors. The culprit wasannotationProcessor 'android.arch.persistence.room:compiler:1.0.0'` in app.gradle dependency.
Hope this helps someone

UPDATE:

To Run I the code fine, I had to Rebuild the project and could see room related errors then only. Check my answer https://stackoverflow.com/questions/48356496/room-annotation-processor-with-data-binding/48379815#48379815

Was this page helpful?
0 / 5 - 0 ratings