1

So I am trying to delete all items in my Room Persistence table, which obviously led me to this :

@Dao 
interface MyDao {
    @Query("DELETE FROM myTableName")
    public void nukeTable();
}

Stack overflow suggestion

However when running ./gradlew lint I am faced with a Restricted API failure as seen below.

Dao_Impl.java

1.My Code

@Dao
public interface AlertDao {

    @Insert
    void insert(List<Alert> alert);

    @Query("SELECT * FROM alert")
    List<Alert> queryAll();

    @Query("DELETE FROM alert")
    void deleteTable();
}
  1. My lint error

Restricted API ../generated/source/apt/debug/com/app/test/storage/dao/AlertDao_Impl.java:>84: SharedSQLiteStatement.acquire can only be called from within the same >library group (groupId=android.arch.persistence.room) 81 82 @Override 83 public void deleteTable() { 84 final SupportSQLiteStatement _stmt = >__preparedStmtOfDeleteTable.acquire();
85 __db.beginTransaction(); 86 try { 87 _stmt.executeUpdateDelete();

../generated/source/apt/debug/com/app/test/storage/dao/AlertDao_Impl.java:91: SharedSQLiteStatement.release can only be called from within the same library group (groupId=android.arch.persistence.room) 88 __db.setTransactionSuccessful(); 89 } finally { 90 __db.endTransaction(); 91 __preparedStmtOfDeleteTable.release(_stmt);
92 } 93 }

../generated/source/apt/debug/com/app/test/storage/dao/AlertDao_Impl.java:98: RoomSQLiteQuery can only be called from within the same library group (groupId=android.arch.persistence.room) 95 @Override 96 public List queryAll() { 97 final String _sql = "SELECT * FROM alert"; 98 final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
99 final Cursor _cursor = __db.query(_statement); 100 try { 101 final int _cursorIndexOfAutoGeneratedKey = _cursor.getColumnIndexOrThrow("autoGeneratedKey");

../generated/source/apt/debug/com/app/test/storage/dao/AlertDao_Impl.java:134: RoomSQLiteQuery.release can only be called from within the same library group (groupId=android.arch.persistence.room) 131 return _result; 132 } finally { 133 _cursor.close(); 134 _statement.release();
135 } 136 } 137 }

Any help would be much appreciated.

Regards

Community
  • 1
  • 1
Gotama
  • 421
  • 4
  • 13

1 Answers1

1

I found somewhat similar issue here Android Architecture Component Issue Tracker. As per the issue they might ignore generated code in linting. Android Architecture Components still in alpha so they are working to fix it.

I used deleteTable() in my application and my DAO looks like

@Query("DELETE FROM tv_show")
void deleteTable();

And it worked for me without giving any lint errors.

D/TVShowViewModel: deleteTVShowTable: Delete

Make sure you are using latest version of architecture components and gradle to avoid any fixed bugs. Find latest release here Android Architecture Components Releases

You can disable RestrictedApi as workaround for now in Android Studio Project gradle file

android {
  lintOptions {
    disable 'RestrictedApi'
  }
}
adityakamble49
  • 1,971
  • 18
  • 27