AOSP build: Api check failed when replacing public java files under frameworks/base/core with prebuilt .jar - android-source

I am compiling Android 8.1 AOSP, I want to remove any specified java files under frameworks/base/services and frameworks/base/core, and build the removed java files into .jar libraries, then add the library to framework to make it compile successfully. I succeeded in frameworks/base/services, but failed with API check when do it in frameworks/base/core.
What I did:
Disable JACK compile tool, modify file build/make/core/combo/javac.mk
ANDROID_COMPILE_WITH_JACK := false
Copy frameworks/base/core/java/android/app/ActivityManager.java to frameworks/base/core/mytest/core/java/ActivityManager.java
Create frameworks/base/core/mytest/Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := frameworks.base.core.mytest
LOCAL_SRC_FILES += \
$(call all-java-files-under,core/java)
# depends on it to make compilition success
LOCAL_JAVA_LIBRARIES := services
include $(BUILD_STATIC_JAVA_LIBRARY)
Run command: mmm frameworks/base/core/mytest
Then it will generat a .jar file: out/target/product/mydevice/obj/JAVA_LIBRARIES/frameworks.base.core.mytest_intermediates/javalib.jar, copy it into prebuilt/mylibs/
Create prebuilt/mylibs/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# my lib is named as 'myam'
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += myam:javalib.jar
include $(BUILD_MULTI_PREBUILT)
Modify frameworks/base/Android.mk, in framework module, add line:
LOCAL_MODULE := framework
# add my lib to framework.jar
LOCAL_STATIC_JAVA_LIBRARIES += myam
REMOVE the original file: rm frameworks/base/core/java/android/app/ActivityManager.java
Run make command to build the AOSP project, I got the error log:
javadoc: error - In doclet class com.google.doclava.Doclava, method start has thrown an exception java.lang.reflect.InvocationTargetException
java.lang.IllegalArgumentException: Unable to find ActivityManager.java. This is usually because doclava has been asked to generate stubs for a file that isn't present in the list of input source files but exists in the input classpath.
at com.google.doclava.Stubs.parseLicenseHeader(Stubs.java:656)
at com.google.doclava.Stubs.writeClassFile(Stubs.java:635)
Where throws the exception is in external/doclava/src/com/google/doclava/Stubs.java:
private static String parseLicenseHeader(/* #Nonnull */ SourcePositionInfo positionInfo) {
//...
File sourceFile = new File(positionInfo.file);
if (!sourceFile.exists()) {
throw new IllegalArgumentException("Unable to find " + sourceFile +
". This is usually because doclava has been asked to generate stubs for a file " +
"that isn't present in the list of input source files but exists in the input " +
"classpath.");
}
Since the source file has been removed, so I specified the source file path to a Stub file that generated by a previous successful built:
out/target/common/obj/JAVA_LIBRARIES/android_system_stubs_current_intermediates/src/android/app/ActivityManager.java, copy it to /data1/myAOSProot/generated/stubs/ActivityManager.java,
private static String parseLicenseHeader(/* #Nonnull */ SourcePositionInfo positionInfo) {
//...
File sourceFile = new File(positionInfo.file);
if (!sourceFile.exists()) {
// As it can't find the source file, I specified it as below:
if (positionInfo.file.equals("ActivityManager.java") || positionInfo.file.endsWith("/ActivityManager.java")) {
sourceFile = new File("/data1/myAOSProot/generated/stubs/ActivityManager.java");
} else {
throw new IllegalArgumentException("Unable to find " + sourceFile +
". This is usually because doclava has been asked to generate stubs for a file " +
"that isn't present in the list of input source files but exists in the input " +
"classpath.");
}
}
But I got a new error:
ActivityManager.java:0: warning: Method android.app.ActivityManager.TaskSnapshot.getSnapshot returns unavailable type GraphicBuffer m.position? ActivityManager.java [110]
ActivityManager.java:0: warning: Method android.app.ActivityManager.getGrantedUriPermissions returns unavailable type ParceledListSlice m.position? ActivityManager.java [110]
ActivityManager.java:0: warning: Method android.app.ActivityManager.getService returns unavailable type IActivityManager m.position? ActivityManager.java [110]
ActivityManager.java:0: warning: Parameter of unavailable type android.content.pm.IPackageDataObserver in android.app.ActivityManager.clearApplicationUserData() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IActivityManager.java:10691: warning: Parameter of hidden type android.app.ContentProviderHolder in android.app.IActivityManager.publishContentProviders() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IApplicationThread.java:2321: warning: Parameter of hidden type android.app.ResultInfo in android.app.IApplicationThread.scheduleSendResult() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IApplicationThread.java:2322: warning: Parameter of hidden type android.app.ResultInfo in android.app.IApplicationThread.scheduleLaunchActivity() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IApplicationThread.java:2341: warning: Parameter of hidden type android.app.ResultInfo in android.app.IApplicationThread.scheduleRelaunchActivity() [110]
This is because of the #hide or #removed comments in GraphicBuffer.java etc., I try ignoring the errors by comment the codes reporting error in external/doclava/src/com/google/doclava/Errors.java:
public static void error(Error error, SourcePositionInfo where, String text) {
// all commented
}
But still, another error:
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/content/pm/ParceledListSlice.java:19: error: cannot find symbol
extends android.content.pm.BaseParceledListSlice<T>
^
symbol: class BaseParceledListSlice
location: package android.content.pm
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/app/IApplicationThread.java:13: error: cannot find symbol
public abstract void scheduleSendResult(android.os.IBinder token, java.util.List<android.app.ResultInfo> results) throws android.os.RemoteException;
^
symbol: class ResultInfo
location: package android.app
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/app/IApplicationThread.java:14: error: cannot find symbol
public abstract void scheduleLaunchActivity(android.content.Intent intent, android.os.IBinder token, int ident, android.content.pm.ActivityInfo info, android.content.res.Configuration curConfig, android.content.res.Configuration overrideConfig, android.content.res.CompatibilityInfo compatInfo, java.lang.String referrer, com.android.internal.app.IVoiceInteractor voiceInteractor, int procState, android.os.Bundle state, android.os.PersistableBundle persistentState, java.util.List<android.app.ResultInfo> pendingResults, java.util.List<com.android.internal.content.ReferrerIntent> pendingNewIntents, boolean notResumed, boolean isForward, android.app.ProfilerInfo profilerInfo) throws android.os.RemoteException;
^
symbol: class ResultInfo
location: package android.app
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/app/IApplicationThread.java:33: error: cannot find symbol
public abstract void scheduleRelaunchActivity(android.os.IBinder token, java.util.List<android.app.ResultInfo> pendingResults, java.util.List<com.android.internal.content.ReferrerIntent> pendingNewIntents, int configChanges, boolean notResumed, android.content.res.Configuration config, android.content.res.Configuration overrideConfig, boolean preserveWindow) throws android.os.RemoteException;
^
symbol: class ResultInfo
location: package android.app
The files reporting error like out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/content/pm/ParceledListSlice.java actually is NOT existed in a NORMAL AOSP compiling, and the file it refers like BaseParceledListSlice.java is just under the same directory as ParceledListSlice.java, I am confused why would this error happen.
Did I miss anything or is there a different way to achieve my goal? I just want to replace java files to .jar libraries.
Anyone could help me out? Thanks a lot!

Related

Jflex and CUP not working on vscode and mac

I downloaded jflex by doing brew install jflex everything worked the way it should.
But now when I'm trying to make it work with java_cup.runtime.*. And I keep getting the errors below
Lexer.java:681: error: cannot find symbol
{ return new java_cup.runtime.Symbol(sym.EOF); }
^
symbol: variable sym
location: class Lexer
My proffesor said,
"The Symbol class is
part of the parser (JavaCUP)’s runtime jar file. You may use it in the lexer simply by
setting the classpath to include the jar file from JavaCUP and importing it"
So I made bash file below and did what he said and it is not working.
#!/bin/bash
jflex MiniJava.jflex
javac -cp "/Users/carlosfield/Desktop/School/csc453/java-cup-bin-11b-20160615/java-cup-11b.jar" Lexer.java
java -cp "/Users/carlosfield/Desktop/School/csc453/java-cup-bin-11b-20160615/java-cup-11b-runtime.jar" Lexer Factorial.java
rm Lexer*
This is my jflex file
import java.util.*;
import java_cup.runtime.*;
%%
%class Lexer
%cup
%line
%column
%{
private Symbol symbol(int type) {
return new Symbol(type, yyline, yycolumn);
}
private Symbol symbol(int type, Object value) {
return new Symbol(type, yyline, yycolumn, value);
}
%}
WhiteSpace = [ \t\r\n]
Identifier = [a-zA-Z_][a-zA-Z0-9_]*
Integer = 0 | [1-9][0-9]*
%%
“+” { }
The fix for this issue is that if you use %cup in your jflex file you must then make your own sym class which contains public static final int EOF=0.

Generics: Type argument is not within its bounds

Any idea why the following code wouldn't compile?
fun <T : Comparable<T>> naturalSort(list: List<T>): List<T> {
val natComparator = naturalOrder<T>() // compiler error here
return list.sortedWith(natComparator)
}
The second line results in the compiler error:
Type argument is not within its bounds: should be subtype of 'Comparable'
Update:
It works for me in https://play.kotlinlang.org/ but fails in Eclipse and when building the project (from Eclipse) with the project's Gradle build script.
Here's how my Gradle build environment looks like:
https://pastebin.com/0GDUWy2C
Solved. The problem was caused by the wrong Comparable interface being used due to import statements in the actual code (no problem with the import statements, not really sure why java.lang.Comparable was used instead of kotlin.Comparable). Specifying in the code that kotlin.Comparable should be used resolves the issue:
fun <T : kotlin.Comparable<T>> naturalSort(list: List<T>): List<T> {
val natComparator = naturalOrder<T>() // no error
return list.sortedWith(natComparator)
}
Thanks to everyone who responded.

How to fix RuntimeException: error reading Scala signature of com.snp.utils.DbUtils: error reading Scala signature

I have defined
var status:String = null;
var error_msg:String = null;
try{ status ="Error"; error_msg= "n/a";
}
When I place my method in DbUtils object and call from my main class it is throwing error, i.e. when calling
DbUtils.writeToCassandraAuditLog(spark, status, error_msg);
it throws below error
2018-10-23 14:03:37 ERROR java.lang.RuntimeException: error reading Scala signature of com.snp.utils.DbUtils: error reading Scala signature of org.apache.spark.sql.package: assertion failed: unsafe symbol Unstable (child of <none>) in runtime reflection universe
at scala.reflect.internal.pickling.UnPickler.unpickle(UnPickler.scala:46)
But when I place/define the methods in my main class/object it is working fine.
writeToCassandraAuditLog(spark, status, error_msg);
How to fix this issue?

Import and usage of different package files in protobuf?

I have imported an other proto which having different package name than mine. For usage of messages from other package, have accessed that message with package name.
For Example :
other.proto
package muthu.other;
message Other{
required float val = 1;
}
myproto.proto
package muthu.test;
import "other.proto";
message MyProto{
required string str = 1;
optional muthu.other.Other.val = 2;
}
Is there a way to use val of muthu.other package directly like optional val = 2; instead of using muthu.other.Other.val ?
Couldn't find any help document regarding this. Help me out.
If the package name is same then you can omit the package name from the field declaration but otherwise there is no other way. if you can include muthu.test in the same package by specifying "package muthu.other" then it is allowed.
From Google documentation of protobuf:
You can add an optional package specifier to a .proto file to prevent name clashes between protocol message types.
package foo.bar;
message Open { ... }
You can then use the package specifier when defining fields of your message type:
message Foo {
...
required foo.bar.Open open = 1;
...
}

Set default value for static method in bootstrap

this paragraph is part of 'Zend Framework In Action' book.
SearchIndexer::setIndexDirectory(ROOT_DIR . '/var/search_index');
Places_Db_Table_Row_Observable::attachObserver('SearchIndexer');
As you can see, it’s simply a case of setting the directory to store the search index files
and attaching the class to the list of observers in Places_Db_Table_Row_Observable
using the name of the class.
Now I have a problem! I put this code in bootstrap file in runapp method, but it can't recognize the directory that I set in bootstrap!
It shows me this error
An error occurred exception 'Zend_Search_Exception' with message 'No index directory specified' in E:\xampp\php\PEAR\Zend\Search\Lucene.php:497
=======================================================
other type of my question :
I have this code in bootstrap file (runApp method):
SearchIndexer::setIndexDirectory(ROOT_DIR.'/var/search_index');
Places_Db_Table_Row_Observable::attachObserver('SearchIndexer');
I set search directory path in SearchIndexer class, but there is a prob!
When I use of below code in controller action, it can't recognize the directory that I set in bootstrap!
controller code :
$index = Places_Search_Lucene::open(SearchIndexer::getIndexDirectory());
this is seachIndexer code :
public static function setIndexDirectory($directory){
if(!is_dir($directory)) {
throw new Exception('Directory for SearchIndexer is invalid ('. $directory .')');
}
self::$_indexDirectory = $directory;
}
public static function getIndexDirectory(){
return self::$_indexDirectory;
}
Your getIndexDirectory function does not return a path so Places_Search_Lucene::open fails.
Maybe setIndexDirectory fails to set the path. Do some debugging on that.
Maybe you use the class in your bootstrap before it gets loaded by zend autoloader. Where do you perform this?
Try to load the class manually before usage:
Zend_Loader::loadClass('Path_To_SearchIndexer',
array(
'/home/production/mylib',
)
);
Documentation on zend loader: http://framework.zend.com/manual/en/zend.loader.load.html