공부/Unity

Android process 의 waitfor() 호출 시 에러

Lero God 2023. 12. 27. 12:19
void Func()
{
	Process process = Runtime.getRuntime().exec(cmd);
	process.waitFor()
}

 

아래는 유니티에서 호출하는 안드로이드 함수 내에서 프로세스를 실행을 하고 기다리기 위해 waitFor 을 호출했을 때 발생하는 컴파일 에러다.

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
F:\Work\Unity_Projects\GSB\Unity\GSBGame\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\src\main\java\com\google\firebase\MessagingUnityPlayerActivity.java:124: error: unreported exception InterruptedException; must be caught or declared to be thrown
           process.waitFor();
                          ^
Note: F:\Work\Unity_Projects\GSB\Unity\GSBGame\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\src\main\java\com\google\firebase\MessagingUnityPlayerActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':unityLibrary:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

 

process 를 실행한 함수에서 IOException 과 InterruptedException 을 던지거나 try catch 문으로 예외를 처리하면 해결된다.

 

waitFor 이 호출될 때 발생하는 예외를 처리하거나 던지지 않으면 발생하는 에러인 듯 하다.

안드로이드에서는 예외를 처리하지 않으면 강제로 에러를 발생시키는 것인가?

void Func() throws InterruptedException, IOException
{
	Process process = Runtime.getRuntime().exec(cmd);
	process.waitFor()
}

//or

void Func()
{
	try
    {
    	Process process = Runtime.getRuntime().exec(cmd);
		process.waitFor()
	}	
	catch( IOException e )
    {
    	...
    }
    catch( InterruptedException e )
    {
    	...
    }
}

 

'공부 > Unity' 카테고리의 다른 글

Unity IL2CPP  (0) 2023.07.21
Async/await with a Func delegate  (0) 2023.07.12